1

I need your help with get a value from created input. I have to get value from input search which is generated by jquery. I have following code but it didn't work:

 $(document).ready(function () {
       $("#raport").click(function() {
        var search = $("#search").val();
        alert (search);
        })    
});

Have you got any ideas?

2
  • 1
    What is generated dynamically? The raport or the search? Or both? Commented Jun 5, 2013 at 10:54
  • Search is generated dynamically. Commented Jun 5, 2013 at 11:06

4 Answers 4

3

You need to create the event in a different way as to work for newly added controls:

$(document).ready(function () {
   $(document).on("click", "#raport" ,function() {
      var search = $("#search").val();
      alert (search);
   });
});

That way the initial listener is added to the document and when an element of id #raport is clicked, even if it is a new control, the code is executed.

Sign up to request clarification or add additional context in comments.

Comments

2

try this for the elements which will come dynamically

$(document).on("click" ,"#raport",function() {

2 Comments

Sorry for being vague, but search is generated dynamically. #Raport button is "normal" Html
I think then there is no problem
1

Assuming it's the #raport element that is generated dynamically, you have to use .on() instead of .click():

$(document).on('click', '#raport', function () {

Comments

0

for example if you added a new recipe in your restaurant application page through AJAX, then just use that food and price in this way.

$('#main_food_div').on('change','input:checkbox', function(){
      //Do your jQuery here
        //alert($(this).attr('id'));
         //alert($(this).val());
});

Comments