phpgoal Posted June 25, 2013 Share Posted June 25, 2013 Hello, I want to insert a row after i click the submit button but no rows get inserted. Please help me! <!DOCTYPE html><html><head><script> window.onload = function(){ var selectElement = document.getElementById('animal'); var selectMonth = document.getElementById('month1'); document.getElementById('year').onsubmit = function(){ var index = selectElement.selectedIndex; var indexM = selectMonth.selectedIndex; var ff = selectElement.options[index].value; var mm = selectMonth.options[indexM].value; }; }; function displayResult(){ for($row=0; $row<1; $row++){var table=document.getElementById("myTable");var row=table.insertRow($row);var cell1=row.insertCell(0);var cell2=row.insertCell(1);cell1.innerHTML="tt";cell2.innerHTML="mm";} }</script></head><body> <form id="year" action="#"><table border = "2"><tr><td> <strong>Select Year</strong> </td> <td> <strong>Select Month </strong></td> </tr><tr><td> <select id="animal" name="animal" class="favAnimal"> <option value="2013">2013</option> <option value="2012">2012</option> </select></td><td> <select id="month1" name="animal" class="favAnimal"> <option value="Jan">January</option> <option value="Feb">Feb</option> <option value="Mar">Mar</option> </select></td> </tr> <tr> <td colspan = "2"> <input type="submit" onclick="displayResult();" value="Submit" /></td></tr></table></form> <br> <table id="myTable" border="1"><tr> <td><b>year</b> </td> <td> <b>month</b></td> </tr></table><br> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/279563-insert-row-onclick/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.