Store form data in a array?

Need help storing form data in an array. The form has an option to display additional fields. How do I get the additional field values to display in the data array.

Please Enter Your First Name Last Name

Please Enter Your Address

var storeData = { "firstname": "", "lastname": "", "address": "", "hour": "" }; $('#btnAdd').click(function() { var num = $('.clonedInput').length; var newNum = new Number(num + 1); var newElem = $('#input' + num).clone().attr('id', 'input' + newNum); newElem.children(':first').attr('id', 'name' + newNum).attr('name', 'name' + newNum); $('#input' + num).after(newElem); }); $('#submit').click(function() { var firstname = $('#first1').val(); var lastname = $('#last1').val(); var address = $('#add1').val(); var hour = $('#hour1').val(); storeData.firstname = firstname; storeData.lastname = lastname; storeData.address = address; storeData.hour = hour; console.log(storeData); }); Here is my working example. Note the first fields values are set in the data array but when you add additional fields they are not.

以上就是Store form data in a array?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准