JavaScript determines whether the radio in the form has an unchecked

Source: Internet
Author: User
Tags return tostring
Javascript| selected

function Getcheckedvalue (radioobj) ... {
if (!radioobj)
Return "";
var radiolength = radioobj.length;
if (radiolength = = undefined)
if (radioobj.checked)
return radioobj.value;
Else
Return "";
for (var i = 0; i < radiolength; i++) ... {
if (radioobj[i].checked) ... {
return radioobj[i].value;
}
}
Return "";
}
function Check ()
... {

for (i = 0; i < document.submitform.all.length i++) ... {
if (Document.submitform.all (i). TagName = = "INPUT") ... {
var oitem = Document.submitform.all.item (i);
var sname = Oitem.name;
if (oitem.type.toLowerCase () = = "Radio") ... {
if (Getcheckedvalue (Document.getelementsbyname (oitem.name)) = = "") ... {
Oitem.focus ();
Window.scrollby (0,-30);
Alert ("Please fill in all the questions carefully.") ");
return (false);
}
}
}
}

Document.submitform.submit ();

}

Getcheckedvalue gets the values of the Radio box,

Return the value of the radio button this is checked
Return a empty string if none are checked, or
There are no radio buttons
function Getcheckedvalue (radioobj) {
if (!radioobj)
Return "";
var radiolength = radioobj.length;
if (radiolength = = undefined)
if (radioobj.checked)
return radioobj.value;
Else
Return "";
for (var i = 0; i < radiolength; i++) {
if (radioobj[i].checked) {
return radioobj[i].value;
}
}
Return "";
}
Set the radio button with the given value as being checked
Do no if there are no radio buttons
If the given value does not exist and all the radio buttons
are reset to unchecked
function Setcheckedvalue (radioobj, NewValue) {
if (!radioobj)
Return
var radiolength = radioobj.length;
if (radiolength = = undefined) {
radioobj.checked = (Radioobj.value = = newvalue.tostring ());
Return
}
for (var i = 0; i < radiolength; i++) {
radioobj[i].checked = false;
if (Radioobj[i].value = = newvalue.tostring ()) {
Radioobj[i].checked = true;
}
}
}

Check function to determine if all of the radio boxes are not selected, if any are displayed.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.