I have a script that create a dynamic table. After the user clicks the button, the next row added to the bottom of the table .:
function createRow() { var options='<select name="nameselect'> options+='<option>one</option>'; options+='</select>'; options+='<input type=\'submit\' name=\'loadReq\' value=\'Pobierz dane\' />'; var form = document.createElement('form'); // create row node var row = document.createElement('tr'); // create row node var col = document.createElement('td'); // create column node var col2 = document.createElement('td'); // create second column node var col3 = document.createElement('td'); // create column node var col4 = document.createElement('td'); // create second column node var col5 = document.createElement('td'); // create column node var col6 = document.createElement('td'); form.appendChild(col); row.appendChild(form); // append first column to row row.appendChild(col2); // append second column to row row.appendChild(col3); // append first column to row row.appendChild(col4); // append second column to row row.appendChild(col5); // append first column to row //row.appendChild(col6); col.innerHTML = options; col2.innerHTML = 'some text'; // put data in second column col3.innerHTML = 'some text'; col4.innerHTML = 'some text'; col5.innerHTML = 'some text'; table.insertAdjacentElement('beforeEnd', row); counter++; }
So now I am adding a row with some text value in 2-5 columns and a drop down list with a button in the form in the first column.
But whenever I submit my form, the page reloads, so the my JavaScript function no longer exists, as a result I get exacly the same page as before, and the line I added disappears,
Is it possible to submit a form and not lose efect JavaScript functions?
source share