user2417624
user2417624

Reputation: 693

get the values from all form elements in onchange event

I have a form, in which I have 15 comboboxes, and one check box. I am trying to get all current values in the form in onchange event.

My code so far:

function update_number_of_adds_found(field_dropdown, selected_value) {
    for (i = 0; i < document.submitadd.elements.length; i++) {
        alert("The field name is: " + document.submitadd.elements[i].name +
            " and it’s value is: " + document.submitadd.elements[i].value);
    }
    // var result5 = $.ajax({
    //   'url': '<?php echo site_url('search/findNumberOfAdds'); ?>/' + selected_value,
    //   'async': false
    // }).responseText;
    // $('#totalNumOfAdds').empty();
    // $("#totalNumOfAdds").append(result5);
}

Code above works so far, that is in the alert i get the values. Now, i would like to place those variables in the variables and send those variables in the ajax request bellow.

Anyone can help me with this? Regards, John

Upvotes: 0

Views: 337

Answers (1)

helion3
helion3

Reputation: 37431

You mentioned jQuery so I assume it's acceptable to you:

$('form').serialize() creates a string for ajax-style data submissions

If you need all the elements, just use $('form').find('input,select,textarea') etc

Upvotes: 3

Related Questions