I want to add data to a selective cell of a table. I wrote this code in JavaScript.
var rowIndex = 10; var colIndex = 5; var dateTable = document.getElementById('timeTable'); dateTable.rows[rowIndex].cells[colIndex].innerHTML = "Su"; I wanted to use the same concept in jQuery as:
$('input[name=add_button]').click(function(e) { var dateTable = document.getElementById('timeTable'); var rowIndex = $('[name=days]').val(); var colIndex = $('[name=times]').val(); var text = $('input[name = text]').val(); dateTable.rows[rowIndex].cells[colIndex].innerHTML = text; e.preventDefault(); }); My problem is: preventDefault() method should prevent my form to be submitted. It is not preventing form submission. If I remove the dateTable.rows[rowIndex].cells[colIndex].innerHTML = text; line, the form is not submitted. I think there is some problem with this particular line. Please help me sorting this. If there is better option available in jQuery please tell me. I shall be able to use the colIndex and rowIndex to find the position of the cell.
Thanks
colIndexandrowIndexmight not being set to what you expect and are in fact undefined. Did you see any error in console ?val()to number. Hard to say you aren't getting errors...form might be submitting faster than errors show in console. Put `preventDefault at begining so if errors occur afterwards form won't submit