|
-
Oct 17th, 2002, 02:19 AM
#1
Thread Starter
Lively Member
how do i validate this - radio button
on my form i got four radio button and i want my user to choose this radio button before they submit it.
what i do:
i create a function named
validateRadio(form)
{
if (form.radiobtt.checked)
{}else
{alert("you must choose one of this radio button");
return false;
}
but with this function, i got error telling me that 'the object does'nt support this....
what wrong and how should i code it the right way
(question from newbie )
-
Oct 17th, 2002, 03:22 AM
#2
try this
Code:
function validateRadio(){
if (!document.frm.rdo.checked)
alert('not checked');
return false;
}
-
Oct 17th, 2002, 03:39 AM
#3
Thread Starter
Lively Member
it works but....
this is my full function:
for (Count = 0; Count < 2; Count++)
{
if (document.frm.frmHakMlk.checked)
{}
else
{
alert ("Please choose your option");
return false;
}
}
but when i click one of the radio button the result is still the same.
it seem that when the user choose the radio button, the function cannot read it. even can't test it! what happend?
-
Oct 17th, 2002, 07:36 AM
#4
Do you have more than one radio button with the same name?
if so then it's an array and should be handled:
Code:
document.frm.frmHakMlk[count].checked
-
Oct 17th, 2002, 08:34 PM
#5
Thread Starter
Lively Member
RESOLVED
OPPS... silly me....
yeah it should be that way. but i just modify it...
not good but ok
if ((document.frm.frmHakMlk[0].checked)|| (document.frm.frmHakMlk[1].checked)|| (document.frm.frmHakMlk[2].checked))
{}
else
{
alert ("Please choose your option");
return false;
}
thanks DeadEye!
-
Oct 20th, 2002, 02:05 PM
#6
To make extension to more radios easier I recommend this function:
Code:
function IsCheckedRadio(rad, num)
{
var ch, i;
for(i=0;i<num;++i)
ch = ch || rad[i].checked;
return ch;
}
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 20th, 2002, 02:09 PM
#7
To implement this in your function you'd do
Code:
if(!IsCheckedRadio(document.frm.frmHakMlk, 3))
alert("bla");
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|