Currently I've two input fields which updates automatically when I press Update button and I want to add more inputs... but problem is I have to add my input field name in jquery script manually. Can we add any loop for this? Please help!!
Type Comment: <input name="mainComment" type="text" value="" />
<input type="button" name="updateComment" value="Update" />
<hr />
<input type="checkbox" class="myCb" name="cb[1]" /><input type="text" name="inv[1]" value="" /><br />
<input type="checkbox" class="myCb" name="cb[2]" /><input type="text" name="inv[2]" value="" />
<script type="text/javascript">
$(document).ready(function() {
$("input[name='updateComment']").live("click", (function(){
if($("input[name='cb[1]']").is(":checked")) {
$("input[name='inv[1]']").val($("input[name='mainComment']").val());
} else {
$("input[name='inv[1]']").val("");
}
if($("input[name='cb[2]']").is(":checked")) {
$("input[name='inv[2]']").val($("input[name='mainComment']").val());
} else {
$("input[name='inv[2]']").val("");
}
}));
});
</script>
.live()is deprecated and removed in newer jQuery versions. I would recommend updating your scripts to.on()