Click to See Complete Forum and Search --> : clearing certain fields in a form


mangeloni
01-28-2003, 07:18 PM
I've already got a form programmed as follows

(o) radio valueA
[text fieldA1*] [menu listA1*] {*validation coded, both must be entered if radio valueA is checked}
[text fieldA2] [menu listA2] {no validation code, optional entry}

(o) radio valueB
[text fieldB1*] [menu listB1*] {*validation coded, both must be entered if radio valueB is checked}
[text fieldB2] [menu listB2] {no validation code, optional entry}

(o) radio valueC

What I also have programmed in is when the user clicks Radio ValueA anything already entered in the text/menu fields in 'B' is cleared...and visa versa. And if the user clicks C, everything in the 'A' and 'B' groups are cleared.

With the following sample Javascript code:

function process(obj){
if(obj.value=="r1"){
document.form1.t3.value = "";
document.form1.t4.value = "";
}else if(obj.value=="r2"){
document.form1.t1.value = "";
document.form1.t2.value = "";
}

<input type="Radio" name="r1" value="r1" onclick="process(this);"></input><br>
<input type="Text" name="t1"></input><br>
<input type="Text" name="t2"></input><br>
<input type="Radio" name="r1" value="r2" onclick="process(this);"></input><br>
<input type="Text" name="t3"></input><br>
<input type="Text" name="t4"></input><br>

HOWEVER...I need to take this one step further. I have found in testing - that if the user clicks radio valueB, THEN enters something text/menu areas for 'A', the 'A' areas do not get cleared out.

I have tried attaching the JS with onChange, onFocus and onBlur on these form fields - but nothing is working. I've even tried to attach to JS to the form tag - no go.

I don't know what the chances are that the use will do this reverse sort of thing - but I am trying to cover all my bases.

Thanks in advance!

~MVA

lmccord2
01-28-2003, 07:28 PM
Ah, I quit JavaScript and forgot most of it and only ask for scripts here, and sometimes, if I remember how to do something write a small code. But I remember how to do this :).

Just put this on a test page and look at it and modify it to what you need. Your other code was confusing me lol.

<Script Language="JavaScript">
<!--Begin--
function clearbox1() {
document.testform.box1.value="";
}

function clearbox2() {
document.testform.box2.value="";
}

function clearbox3() {
document.testform.box3.value="";
}
//End-->
</Script>

<Form name="testform">
<input type="text" value="BOX 1" name="box1"><BR>
<input type="button" value="Clear Box 1" onclick="clearbox1()"><BR><BR>

<input type="text" value="BOX 2" name="box2"><BR>
<input type="button" value="Clear Box 2" onclick="clearbox2()"><BR><BR>

<input type="text" value="BOX 3" name="box3"><BR>
<input type="button" value="Clear Box 3" onclick="clearbox3()">