Click to See Complete Forum and Search --> : Radio Buttons


dcjones
01-29-2003, 12:18 PM
Hi all,

Can you advise me on how to resolve this problem.

I have a from with 2 radio buttons,

What I want to happen is, when button A is check do not check the contents of field X. If button B is checked, check to make sure that the is an entry in fied X.

This is the script:

if (document.mail.VATYES.checked==true) {
alert("You answered yes to VAT registration, please enter your VAT company registration No.");
return false;
}

The HTML part:

<td colspan="2"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">VAT
Registered</font></td>
<td colspan="4"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Yes
<input type="radio" name="VAT" value="radiobutton">
No
<input type="radio" name="VAT" value="radiobutton">
</font></td>
<td width="32%">&nbsp;</td>

Does this make sense.


Many thanks in advance


Dereck

khalidali63
01-29-2003, 03:37 PM
try the code snippedt below

cheers

Khalid


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-5"></meta>
<meta name="Author" content="Khalid Ali"></meta>
<title>Untitled</title>
<script type="text/javascript">
function process(){
for(x=0;x<document.mail.length;x++){
var obj = document.mail[x];
if(obj.type=="radio" && obj.checked){
alert("You answered yes to VAT registration, please enter your VAT company registration No.");
return false;
}
}

return false;
}
</script>
</head>

<body>
<form name="mail" onsubmit="return process();">
<td colspan="2"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">VAT
Registered</font></td>
<td colspan="4">
<font color="#000000" size="2" face="Arial, Helvetica, sans-serif">Yes
<input type="radio" name="VAT" value="vatyes">
No
<input type="radio" name="VAT" value="vatno">
</font></td>
<td width="32%">
<input type="Submit"></input> </td>
</form>

</body>
</html>

Dan Drillich
01-29-2003, 03:49 PM
You can also try -


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example</title>
</head>
<body>
<script type="text/javascript">
<!--
function verify() {

var grp = document.buttons.VAT;
var j, len = grp.length;
for (j=0; j<len; j++) {
if (grp[j].checked) break;
}
if (j<len) {
if (grp[j].value == "a2") {
if (document.buttons.x.value != "") {
return true;
}
}
}

return false;

}
// -->
</script>

VAT Registered
<br>
<form name="buttons" action="http://www.iwon.com" onsubmit="return verify();" >
Yes
<input type="radio" name="VAT" value="a1">
No
<input type="radio" name="VAT" value="a2">
<br>
x - <input type="text" name="x" value="">
<br>
<input type="submit">

</form>



</body>
</html>

Cheers,
Dan

dcjones
01-29-2003, 04:02 PM
Hi and thanks for your reply.

I have tried the script but it does not work
If I select VAT no it displays the error

If I select VAT Yes it displays the error

What I want it to do is if I select VAT YES and I do not input the VAT number I want the error message to appear.

If I select VAT NO i want the script not to show the error message.


Any ideas my friend.

Regards


Dereck