JavaScript.

Transfer data from one page to another using php

Steps:

1:Create new php file and copy file1 code and save it as file1.php.

2.Create another new php file and copy file2 code and save it as file2.php.

3.Run file1.php, then it will display the file1 data.

4.Enter your name, age and location and press the submit button.

5.It will transfer to file2.php and displays the output.

file1:

[php]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>table1</title>
<script language="javascript" type="text/javascript">
function check()
{
if(document.getElementById(‘name1’).value==”)
{
alert("Please enter your name");
document.getElementById(‘name1’).focus();
}
else if(document.getElementById(‘age1’).value==”)
{
alert("please enter your age");
document.getElementById(‘age1’).focus();
}
else if(document.getElementById(‘location1’).value==”)
{
alert("please enter the location");
document.getElementById(‘location1’).focus();
}
else
{
document.form.submit();
}
}
</script>
</head>

<body>
<form method="post" action="file2.php" name="form" >
<table width="100%" border="0">
<tr>
<td><label>Enter your name: </label>
</td>
<td><input type="text" name="name"  id="name1"; />
</td>
</tr>
<tr>
<td><label>Enter your age:</label>
</td>
<td><input type="text" name="age" id="age1"; />
</td>
</tr>
<tr>
<td><label>Enter the location:</label>
</td>
<td><input type="text" name="location" id="location1"; />
</td>
</tr>
<tr>
<td colspan="2"> <div align="center">
<input type="button" value="Submit" onclick="check();" name="Submit" />

</div></td>
</tr>
</table>
</form>
</body>
</html>

[/php]

//save this as file1.php

It will display the output as:

file2:

[php]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>table2</title>
</head>

<body>
<?php
$var1=$_POST[‘name’];
$var2=$_POST[‘age’];
$var3=$_POST[‘location’];
echo "your name is: $var1"."<br/>";
echo "your age is: $var2"."<br/>";
echo "loaction is: $var3";
?>
</body>
</html>

[/php]

//save this as file2.php

after entering your name, age and location and pressing the submit button, it displays the output.

For example:

your name is: John
your age is: 25
loaction is: CA

Tags: , ,

javascript-displays the alert message

Create new html file and copy the code and save it as popup.html.

popup.html

[html]
<strong> </strong><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
function popup()
{
alert("Good morning");
}
</script>
</head>

<body>
<input type="button" onClick="popup()" value="clickhere" />
</body>
</html>
[/html]

It displays the output clickhere button which displays the alert message as “Good morning”

Tags:

Ajax

The term AJAX referred as “Asynchronous JavaScript And XML,” but is now used much more generally to cover all methods of communicating with a server using JavaScript.

Using the Ajax techniques we can submit server requests and get the information from the server to the user without the necessity of waiting for a page load. The page update without refresh was done by Javascript, PHP and XML’s XMLHTTPRequest object.

Ajax is actually a grouping of several technologies working together to offer this capability. This could include the techniques bellow,

  • Ajax offer standards-based presentation using XHTML and CSS.
  • Client, server interaction made using DOM( Document Object Model) and provide dynamic display.

  • Data interchange and manipulation was performed by XML and XSLT.
  • Asynchronous data recovery using XMLHttpRequest.

  • And make JavaScript binding with everything together.

Tags: ,

Request a Free SEO Quote