Abdul Muqeet Abdul Muqeet - 1 year ago 106
Javascript Question

Iterate to div to get different input field and post it to controller

I have a main div that have class models and in this div I have different input type I want to iterate through main div with class models and get the the different input fields and post it to my controller but end up with this error. ReferenceError: getElementsByClassName is not defined

$("#Visitor-form").on("submit", function () {
//Code: Action (like ajax...)
var slides = getElementsByClassName("models");
for (i = 0; i < slides.length; i++) {

var previsitor = [
{ NIC: slides[0].value, V_Name: slides[0].value }
previsitors = JSON.stringify({ 'things': previsitor });

contentType: 'application/json; charset=utf-8',
dataType: 'json',
type: 'POST',
url: '/PreVisitor/addMultipleVisitor',
data: things,
success: function () {
$('#result').html('"Pass List<PreVisitor>" successfully called.');
failure: function (response) {


Answer Source

if you use jquery stick with jquery

 var slides = $(".models");

you forgot the document object in your current syntax

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download