|
 |
asp_web_howto thread: Radiobutton Validation
Message #1 by "David Smith" <deveds2@d...> on Thu, 28 Feb 2002 21:05:38
|
|
I have been researching for a couple of hours on how to make sure a user
selects ONE radio button out of a group. ALL examples that I have found
are radio buttons in conjunction with other form fields - pulldowns, other
radiobutton groups, etc.
How do I take ONE group of radio buttons and make SURE that the user
selected one?
Simple right?
David
http://www.deved.com
Message #2 by "Debreceni, David" <Debreceni.David@h...> on Thu, 28 Feb 2002 16:22:55 -0500
|
|
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C1C09E.160E3480
Content-Type: text/plain;
charset="iso-8859-1"
here is a script I use for validating, I have to admit I stole it from
somewhere else :-)
hope it helps.
function hasValue(obj, obj_type)
{
if (obj_type == "TEXT" || obj_type == "PASSWORD")
{
if ((obj.value.length == 0) || (obj.value.match(/^\s+$/) != null)) {
return false;
}
else
return true;
}
else if (obj_type == "SELECT")
{
for (i=0; i < obj.length; i++)
{
if (obj.options[i].selected){
if (obj.options[i].value.length == 0 ||
(obj.options[i].value.match(/^\s+$/) != null))
return false;
else
return true;
}
}
return false;
}
else if (obj_type == "SINGLE_VALUE_RADIO" || obj_type ==
"SINGLE_VALUE_CHECKBOX")
{
if (obj.checked)
return true;
else
return false;
}
else if (obj_type == "RADIO" || obj_type == "CHECKBOX")
{
for (i=0; i < obj.length; i++)
{
if (obj[i].checked)
return true;
}
return false;
}
}
function checkpage(this_obj){
var error_msg = ""
//checks the text boxes and fields for values that are required
if (!hasValue(this_obj.DealerNum, "RADIO" )) {
error_msg = error_msg + "The Dealer Number is required.\n";
}
if (error_msg.length != 0) {
alert(error_msg);
error_msg = "";
return false; }
else
return true;
}
David Debreceni
Senior Visual Basic/ASP Developer
xxx-xxx-xxxx x 1086
-----Original Message-----
From: David Smith [mailto:deveds2@d...]
Sent: Thursday, February 28, 2002 4:06 PM
To: ASP Web HowTo
Subject: [asp_web_howto] Radiobutton Validation
I have been researching for a couple of hours on how to make sure a user
selects ONE radio button out of a group. ALL examples that I have found
are radio buttons in conjunction with other form fields - pulldowns, other
radiobutton groups, etc.
How do I take ONE group of radio buttons and make SURE that the user
selected one?
Simple right?
David
http://www.deved.com
$subst('Email.Unsub').
|
|
 |