Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery multiple forms per page

I have a page which dynamically creates multiple forms, each form had a unique "id" Within each form is one hidden input field always with the same"id" and "name"

What I am wanting to do is with each form to be able to do an ajax(post) call, which I can do, my issue is getting the input field value from the from ..

So I can get the

    $(document).ready(function() {



var n = $("form").size();
alert('there are ' + n + ' forms');

$('form').submit(function(event){
    event.preventDefault();

    var formName = $(this).attr('id');
    alert(formName);

});

});

So what I amnting to do is to get the value of the input field in the form that has been triggered, the id is held in the var formName

I have been stabbing away but getting no-where fast...

Thanks

Simon

like image 809
Simon Avatar asked Jan 19 '26 00:01

Simon


1 Answers

Put your hidden element ID into the find(). And make .ajax() with passing hiddenValue to data.

$('form').submit(function(event){
    event.preventDefault();
    var hiddenValue = $(this).find('#id-of-hidden').val();
});
like image 88
Alex Pliutau Avatar answered Jan 21 '26 13:01

Alex Pliutau



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!