Monday, February 21, 2011

jQuery post parameter to load

How do I pass the values of txtname and tel as variables to the .load???

$(document).ready(function(){
    $("#add").click(function(){
        $("#result").load("add.php", {name: #txtname});
    });
});

The html:

<p>Name:<input type="text" name="name" value="" id="txtname" /></p>
<p>Telephone:<input type="text" name="tel" id="tel" value="" /></p>
<input type="submit" value="Submit" id="add" />
From stackoverflow
  • $(document).ready(function(){
      $("#add").click(function(){
        $("#result").load("add.php", {
          'name': $("#txtname").val(), 
          'telephone': $("#tel").val()
        });
      });
    });
    
  • $(document).ready(function() {
        $("#add").click(function() {
           $("#result").load("add.php", {
               name: $("#txtname").val(), 
               tel: $("#tel").val()
           });
        });
    });
    

0 comments:

Post a Comment