Click to See Complete Forum and Search --> : possible onClick event?
mangeloni
01-18-2003, 01:07 AM
I would like to have 3 radio buttons (each putting a different value into the same field), which when only one of the three radios is clicked, it clears out any data entered in another text and/or menu field(s).
Is this even possible? I have looked around the BBs and haven't found anything. I am a newbie to JS ~ so detailed help would be greatly appreciated!
~MVA
khalidali63
01-18-2003, 01:12 AM
do you want to have 3 radio buttons,
2 will put a certain value in a single text field and a third radio button will clear the text from that text field?
mangeloni
01-18-2003, 01:33 AM
I've already got the 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
So what I want to do is...
If the user enters a value in text fieldA1/2 and/or menu listA1/2 -BUT- checks radio valueB, I want the values in previous text/menu fields cleared.
The same would be said if the user checked radio optionA, as the values entered in text/menu fields for B are removed. And if radio valueC is checked, and if anything is entered for text/menu fields for either A or B, they are respectively cleared.
I am using Yaromat's check form UDev Extension for the above validation - but I cannot reverse the validation logic (even by custom coding the extension) - so trying to clear the data upon an onClick event seems to be an option.
Other than clearing the data - could it just not enter the values into the DB upon the onSubmit? Is that possible?
~MVA
khalidali63
01-18-2003, 02:06 AM
Is this something that ould work for you?
Khalid
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form name="form1">
<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>
</form>
<script language="JavaScript1.2">
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 = "";
}
}
</script>
</body>
</html>
mangeloni
01-19-2003, 09:37 PM
works great! thanks!
except now I have found the following reversed problem:
If the user clicks radio valueB first, but (for some reason) enters text in text fieldA1 or any other text/menu list for 'A' - those values for 'A' 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 basis.
Thanks!
-Maria