Wednesday, July 11, 2007

Submit form with jQuery

Submit form with jQuery


posting.php file
<script language="javascript" src="js/jquery-1.6.3.min.js" type="text/javascript"></script>
<form id="myform" name="myform" action="postdata.php" method="post">
  <input type="text" id="nm" name="nm" />
  <input type="submit" value="Go" />
  <span id="errorspan"></span>
</form>
<div id="banner">
  Submit form with jQuery.
</div>
<script>
$('#myform').submit(function() {
  if($("#nm").val()=="") {
      $("#errorspan").text("Not valid!").show().fadeOut(3000);
      return false;
  } else {
      return true;
  }
});

$('#banner').click(function() {
  $('#myform').submit();
});
</script>



postdata.php file
<?php
echo $_POST['nm'];


?>


No comments:

Post a Comment