Form And Result at Same Page using Get method Script

Form And Result at Same Page using Get method script is use to when you type and submit a form in the data will pass to through GET method and result will be display same page.

Demo :



Enter your age :  

Example :

Just type a age at text box and click a button then output will display "You're a child" or "You're an adult" message at same form.

Code :

Following code is use to Form And Result at Same Page using Get method Script if you need to copy and use to your website.


<script>
function validate()
{
  if(document.frm.age.value=='')
  {
    alert('Please Enter Age');
    document.frm.age.focus();
    return false;
  }
}
</script>
<?php
  if (!$_GET['submit'])
  {
?>
<h3 style="padding-left:200px; color:#CC0033">Form :</h3>
<form action="<?=$_SERVER['PHP_SELF']?>" method="get" name="frm" id="frm" onsubmit="return validate()">
  Enter your age :   <input name="age" size="2" maxlength="2" style="border:1px solid #A3D6F9" >
  <input type="submit" name="submit" value="Click">
</form>
<?php
}
else
{
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="get" name="frm" id="frm" onsubmit="return validate()">
<h3 style="color:#CC0033">Result :</h3>
<?
  $age = $_GET['age'];
  echo ($age >= 21) ? "<b>You're an adult</b>" : "<b>You're a child</b>";
  ?>
</form>
<?php
}
?>

In the above validate() function is use to form validation.In the above $_SERVER['PHP_SELF'] variable is use to call to same page.

Free Download Script :

If you need Form And Result at Same Page using Get method Script click and download from following link.

Download




Content