How to Obtain form input fields using jQuery?

0 votes
I have a form with many input fields.

When I catch the submit form event with jQuery, is it possible to get all the input fields of that form in an associative array?
Sep 18 in Java-Script by kartik
• 30,230 points
21 views

1 answer to this question.

0 votes

Hello @kartik,

Try this:

$('#myForm').submit(function() {
    // get all the inputs into an array.
    var $inputs = $('#myForm :input');

    // not sure if you wanted this, but I thought I'd add it.
    // get an associative array of just the values.
    var values = {};
    $inputs.each(function() {
        values[this.name] = $(this).val();
    });

});

Hope it helps!!

Thank You!!

answered Sep 18 by Niroj
• 65,500 points

Related Questions In Java-Script

0 votes
1 answer

How to Abort Ajax requests using jQuery?

Hello kartik, Just use ajax.abort(). For example you could ...READ MORE

answered Apr 27 in Java-Script by Niroj
• 65,500 points
481 views
0 votes
1 answer
0 votes
1 answer

How to send data in request body with a GET when using jQuery $.ajax()?

Hello @kartik, Sending the data in your scenario,I ...READ MORE

answered Jun 18 in Java-Script by Niroj
• 65,500 points
2,468 views
0 votes
1 answer

How to get “value” of file upload input field in jquery?

Hello @kartik, Yes ,you can read the value ...READ MORE

answered Jul 7 in Java-Script by Niroj
• 65,500 points
536 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 65,500 points
2,674 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18 in Laravel by Niroj
• 65,500 points
322 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23 in Laravel by Niroj
• 65,500 points
220 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23 in Laravel by Niroj
• 65,500 points
3,325 views
0 votes
1 answer
0 votes
1 answer

How do I add arbitrary html attributes to input fields on a form?

Hello @kartik, If you are using ModelForm, apart from ...READ MORE

answered Jul 27 in Java-Script by Niroj
• 65,500 points
48 views