views:

40

answers:

3

There is one form with a textbox id="name" and a button.

After the user clicks the button, I want to execute the $.get() to capture the reply. (I got the .click() correctly so far)

How to I pass the value the user enters to the text box as the {data} parameter in the get function?

Thank you!

+2  A: 
$.get("user_clicked_handler.php", { name: $("#name").val() },
   function(data){
     alert("Data Loaded: " + data);
   });

Calling $("#name").val() returns value of input box.

Michal Drozd
Thank you very much!
john
+2  A: 

You can do like:

$('.button_class').click(function(){
  var val = $('#name').val();

  $.get('example.php', {name: val}, function(data) {
   alert(data);
  });

});
Sarfraz
+2  A: 

This Stack Overflow page was the first thing that came up on Google.

jQuery has a page about the val() method.

The data is stored in $("input#name").val();

eje211
Many thanks for answering!
john