Wednesday 16 April 2014

Complete jquery form & data delivery

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("#result").load("test.php");
  });
 
  $("#test").click(function(){
       

    //form_submit("reg","test.php");
   
    //get_form("test1.php","result");
   
    //$.ajax({type:"POST",url:"test.php", data: $("#reg").serialize(),success: function(data){alert(data);}});
   
    //$.ajax({type:"GET",url:"test1.php", success: function(data){alert(data);}});

    return false;
   
  });
 
  function  form_submit(form_id,filename,output)
  {

    $.post(filename,$("#"+form_id).serialize(), function(data){if(output){$("#"+output).html(data);}else{alert(data);}});
    }
   
   
    function get_form(filename,output)
    {
       
        $.get(filename, function(data){if(output){$("#"+output).html(data);}else{alert(data);}});
       
    }
 

 
 
});


 function numbersonly(e)
  {
        var unicode=e.charCode? e.charCode : e.keyCode
        if (unicode!=8){ //if the key isn't the backspace key (which we should allow)
        if (unicode<48||unicode>57) //if not a number
        return false //disable key press
        }
    }

</script>
</head>
<body>


<table width="386" border="1">
  <tr>
    <td width="376" height="74"><div id="result"></div></td>
  </tr>
  <tr>
    <td height="25"><button>Get External Content</button></td>
  </tr>
  <tr>
    <td>
   
<form method="post" id="reg">
<input type="text" name="name">

Number <input type="text" name="number" onKeyPress="return numbersonly(event)">
<input type="submit" value="Post Method" id="test">
</form>



</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>









</body>

No comments:

Post a Comment