Jump to content

save html after insertRow()


GuardianZ
 Share

Recommended Posts

this is the javascript function I used:

function insertrow() {            var x=document.getElementById("maintable").insertRow(2);            x.bgColor="#C0C9D4";                        x.innerHTML="<td class='ns'><input type='button' onclick='insertrow()' value='+'/></td> \             	 <td>1</td> \             	 <td class='act'><textarea wrap='virtual' cols=28 rows=1 onchange='checksize(this)' onKeyUp='inc_lines(this)' name='act' type='text' id='text1'></textarea></td> \             	 <td class='in'><textarea wrap='virtual' cols=28 rows=1 onchange='checksize(this)'onKeyUp='inc_lines(this)'  name='in' id='inp'></textarea></td> \             	 <td class='ex'><textarea wrap='virtual' cols=28 rows=1 onchange='checksizethis)'onKeyUp='inc_lines(this)'  name='ex'id='er'></textarea></td> \             	 <td><input type='checkbox' /></td> \             	 <td><input id='fail' type='checkbox' onMouseUp='alertId2()'/></td> \             	 <td><input type='checkbox' /></td> \             	 <td class='com'><textarea wrap='virtual' cols=28 rows=1 onchange='checksize(this)'onKeyUp='inc_lines(this)' id='com' ></textarea></td> \             	 <td class='bi'><textarea wrap='virtual' cols=28 rows=1 onchange='checksize(this)'onKeyUp='inc_lines(this)'  name='bugid' id ='bi'></textarea></td></tr>";                                      }

it is called with

<td class="ns"><form><input type="button" onclick="insertrow()" value="+"/></form></td>

Link to comment
Share on other sites

you can easily set the classname by

x.className = 'theClassName';

this is how you create the elements and have them display

<html><head><title>x</title><script type="text/javascript">function insertrow() {	var x=document.getElementById("maintable");	var newRow = x.insertRow(2);        newRow.style.background="#C0C9D4";    var td1 = document.createElement("TD")    	td1.appendChild(document.createTextNode("column 1"))	newRow.appendChild(td1);}</script></head><body><table id="maintable"><tr><td class="ns"><form><input type="button" onclick="insertrow()" value="+"/></form></td></tr></table></body></html>

You are creating a row so you have to create the columns aswell (you cannot use row.innerHTML) then you can put the proper text in the columns you created.

Link to comment
Share on other sites

That is because the javascript added it. It is not essentially part of the document. If you were to refresh the page it would be gone. There is no way to add it to the source code with javascript.For that you will need a server side language.Why does it have to go into the source code? Are you intending to save the source code to a different file or something?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...