JQuery.get () - How do I pass a text field value to a data parameter?

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

After the user clicks the button, I want to execute $.get()to capture the answer. (So ​​far I have received .click ())

How to pass the value that the user enters into the text field as the {data} parameter in the get function?

Thank!

+3
source share
3 answers

You can do this:

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

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

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

Call $ ("# name"). val () returns the value of the input field.

+2
source

, Google.

jQuery val().

$("input#name").val();

+2

Source: https://habr.com/ru/post/1756409/


All Articles