Let’s say I have an input: <input type="text" id="smth" value="" /> and I have jQuery to pass this data to .php file
$("#submit_button").click(function() {
var info = {};
info['smth'] = $('#smth').val();
$.ajax({
type: "POST",
url: "insert.php",
data: info,
success: function(msg){
alert("Well done!");
}
})
})
It works great, but let’s say I need to add new input, let’s say:
<input type="text" id="smth2" value="" />,
so I need in jQuery add this line after info['smth']:
info['smth2'] = $('#smth2').val();.
My question is, how can I avoid this? Is it possible to not add new line in jQuery every time I add new input? How would it look like? Thanks.
Hopefully, you’re adding all your
<input>s to a<form>. Hopefully, all those<input>s havenameattributes (eg your first one should havename="smth"). In this case, the problem is solved for you!Done!