Forum Moderators: open

Message Too Old, No Replies

Reset Button

how to do a reset button in JS

         

nalini878

6:25 pm on Apr 17, 2005 (gmt 0)

10+ Year Member



Hi,

Wonder if you can help,

I have included reset button on a form that is linked to some Javascript. The form contains a table that manipulates the DOM (a table). But I dont know how to write the script for the reset button.

Below is the J/S and form so far

<table id="myTable" bgcolor="yellow" border="2">
<tbody>
<tr>
<td valign="top">nonsense</td>
<td valign="top">nonsense</td>
<td>nonsense</td>
</tr>
<tr>
<td>nonsense</td>
<td>nonsense</td>
<td>nonsense</td>
</tr>
</tbody>
</table>
<br>
<form> <input onclick="content()" value="Change Content"
type="button"><br>
<br>
<input onclick="color()" value="Change the Color"
type="button"> <br>
<br>
<input value="Reset" type="reset"> </form>
<script language="JavaScript">

// This is a recursive function (it calls itself to process child nodes)
// Parameter 1 : a window reference (where output will be sent)
// Parameter 2 : a DOM element node to be processed
// Parameter 3 : the level in the tree (used for indenting display)

function display(win, node, level){
// If the node does not have a tag name, then it must be the contents
// of the tag/element (ie. ordinary text) so we'll simply return
if(!node.tagName)
return;
// Output some spaces to indent the display according to the tree level
for(var i=0; i<level; i++){
win.document.write(" ");
}
// Now output the tag/element name
win.document.writeln(node.tagName);
// Now process any child nodes recursively
for(var j=0; j<node.childNodes.length; j++){
display(win, node.childNodes[j], level+1);
}
}

var output = open("", "", "toolbar=0,status=0,menubar=0,resizable=1");
output.document.writeln("<pre>");
display(output, document.documentElement, 0);
output.document.writeln("</pre>");
output.document.close();

function content()
{
for (w=0; w<2; w++){
for (z=0; z<3; z++){

var x=document.getElementById('myTable').rows
var y=x[w].cells
y[z].innerHTML="webtech"}}}

function color()
{
document.getElementById('myTable').bgColor="green";
}

</script>

Would be great if anyone could help

cmatcme

3:19 pm on Apr 18, 2005 (gmt 0)

10+ Year Member



Misread your question.

cmatcme

edit: misread question :o realized at 4:21pm