Click to See Complete Forum and Search --> : Radio button value & text area validation


shanuragu
06-09-2003, 11:34 PM
HI
I have two radio buttons whose value is O & D respectively.

If o is checked a text area with a name remarks should be made mandatory field. Please tell me what is wrong in the following code.
here is the code:

if(document.form.ord_status.checked)
{
alert(1);
if(document.form.ord_status.value='O')
{
alert(2);
if (document.form.remarks.value=="")
{
alert(3);
alert("Cannot leave balnk.. Enter Remarks for Outstanding Status.. ");
document.form.remrks.focus();
return false;
}
}
}

ShaRa:confused:

pyro
06-10-2003, 07:54 AM
Try something like this:

<html>
<head>

<script language="JavaScript" type="text/JavaScript">
function checkForm(frm) {
if (frm.ord_status[0].checked) {
if (frm.mytext.value == "") {
alert ("Textbox must be filled out");
}
}
}
</script>

</head>

<body>
<form name="myform">
O <input type="radio" name="ord_status" value="O">
D <input type="radio" name="ord_status" value="D">
<input type="text" name="mytext">
<input type="button" name="mybutton" value="Check" onclick="checkForm(this.form);">
</form>
</body>
</html>

When you reference radio buttons, it is returned in an array. That is why if(document.form.ord_status.checked) didn't work for you.

shanuragu
06-10-2003, 08:05 AM
Thanks Pyro
Its working great!!

ShaRa:D

pyro
06-10-2003, 08:10 AM
You're welcome...

Cheers. :D