PDA

View Full Version : can you clear a section of a form?


helpplease
07-22-2002, 11:43 PM
Hi!
I was wondering if anyone knew if you could clear a section of a form. I know there is a clear input button, but that seems to clear the whole form. I just need it to clear a certain section of my form.
Thanks for any help!
:cool:

Kevlar
07-23-2002, 12:48 AM
Try this:

<form name="form11">
<input type="text" name="n0" value="Something you DONT want to clear"> <p>
<input type="text" name="n1" value="Something you DONT want to clear"><p>
<input type="text" name="n2" value="Something you DONT want to clear"><p>
<input type="text" name="n3" value="Something you DONT want to clear"><p>
<input type="text" name="n4" value="Something you DONT want to clear"><p>
<hr>
<input type="text" name="y1" value="Something you want to clear"> <p>
<input type="text" name="y2" value="Something you want to clear"><p>
<input type="text" name="y3" value="Something you want to clear"><p>
<input type="text" name="y4" value="Something you want to clear"><p>
<input type="text" name="y5" value="Something you want to clear"><p>

<p><p><p><input type="button" value="clear" onClick="document.form11.y1.value='';document.form11.y2.value='';document.form11.y3.value='';document.form11. y4.value='';document.form11.y5.value=''; ">
</form>

// And yes, it is all still one form.

helpplease
07-23-2002, 12:50 AM
Thanks a lot... I'll try it out!

Kevlar
07-24-2002, 06:43 AM
<form name="form11">
<input type="radio" name="n0" value="Something you DONT want to clear" checked> <p>
<input type="radio" name="n1" value="Something you DONT want to clear" checked><p>
<input type="checkbox" name="n2" value="Something you DONT want to clear" checked><p>
<input type="checkbox" name="n3" value="Something you DONT want to clear" checked><p>
<input type="checkbox" name="n4" value="Something you DONT want to clear" checked><p>
<hr>
<input type="radio" name="y1" value="h" checked> <p>
<input type="radio" name="y2" value="Something you want to clear" checked ><p>
<input type="checkbox" name="y3" value="Something you want to clear" checked><p>
<input type="checkbox" name="y4" value="Something you want to clear" checked><p>
<input type="checkbox" name="y5" value="Something you want to clear" checked><p>

<p><p><p><input type="button" value="clear" onClick="document.form11.y1.checked=0;document.form11.y2.checked=0;document.form11.y3.checked=0;document.form 11.y4.checked=0;document.form11.y5.checked=0; ">
</form>

For clearing checkboxes and radio elements.

helpplease
07-24-2002, 08:24 AM
You're the best! Thanks.

adios
07-24-2002, 08:53 PM
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="javascript">

var section1 = new Array('t1','t2','r1','c1','c2'); //element names
var section2 = new Array('t3','t4','r2','c3','c4');

function resetsec(el_names,form) {
var currEl;
for (var i=0; i<el_names.length; ++i) {
currEl = form[el_names[i]];
if (currEl.type == 'text') currEl.value = currEl.defaultValue;
else if (currEl.type == 'checkbox') currEl.checked = currEl.defaultChecked;
else if (currEl.constructor == Array && currEl[0].type == 'radio') {
for (var j=0; j<currEl.length; ++j) currEl[j].checked = currEl[j].defaultChecked;
}
}
}

</script>
</head>
<body>
<form><b>1</b><hr>
<input name="t1" type="text" value="original"><br>
<input name="t2" type="text"><br>
<input name="r1" type="radio"><br>
<input name="r1" type="radio"><br>
<input name="r1" type="radio"><br>
<input name="c1" type="checkbox"><br>
<input name="c2" type="checkbox">
<hr><b>2</b><hr>
<input name="t3" type="text"><br>
<input name="t4" type="text" value="default text"><br>
<input name="r2" type="radio" checked="checked"><br>
<input name="r2" type="radio"><br>
<input name="r2" type="radio"><br>
<input name="c3" type="checkbox" checked="checked"><br>
<input name="c4" type="checkbox"><hr>
<input type="button" value="RESET SECTION 1" onclick="resetsec(section1,this.form)">
<input type="button" value="RESET SECTION 2" onclick="resetsec(section2,this.form)">
</body>
</html>