Because of the death of a radio button problem, n more people come out of the nonsense, alas, I this rookie level figure also come out, mixed water to touch fish. A careless also touched a piece.
First look at a piece of code dug out of Baidu, I started from here.
Copy Code code as follows:
<script>
function Checkradio ()
{
for (i=0;i<document.form1.fruit.length;i++)
{
if (document.form1.fruit[i].checked)
{
Alert ("Your favorite fruit is:" +document.form1.fruit[i].nextsibling.nodevalue);
}
}
}
</script>
<form name= "Form1" >
Your favorite fruit is:<br>.
<input type=radio value= "Fruit1" name= "Fruit" checked> apple
<input type=radio value= "Fruit2" name= "Fruit" > Bananas
<input type=radio value= "Fruit3" name= "Fruit" > Strawberry
<input type=radio value= "FRUIT4" name= "Fruit" > Pineapple
<input Type=button value= "select" onclick= "Checkradio ()" >
</form>
The purpose of this code is to determine the selected value.
The effect now is to give a hint if each option is empty, and the following code is the effect of the changes I have made
Program code
<script>
function Checkradio ()
{
var j=0;
for (i=0;i<document.form1.fruit.length;i++)
{
if (document.form1.fruit[i].checked==true)
{
Alert ("You have selected" +document.form1.fruit[i].nextsibling.nodevalue);
break; This break is a fly-pointing, invalid, removed
}else{
j=j+1;
if (j==4) {
Alert ("Rely on, you TMD choose one, I don't have to come out of karma!" ");
}
}
}
}
</script>
<form name= "Form1" >
Your favorite fruit is:<br>.
<input type=radio value= "Fruit1" name= "Fruit" >
Apple
<input type=radio value= "Fruit2" name= "Fruit" > Bananas
<input type=radio value= "Fruit3" name= "Fruit" > Strawberry
<input type=radio value= "FRUIT4" name= "Fruit" > Pineapple
<input Type=button value= "select" onclick= "Checkradio ()" >
</form>
Then I saw a clearer piece of code written by morning and posted here.
(Note: In order to be easy to test, change a bit, thinking or his ideas)
Copy Code code as follows:
<script>
function Checkradio ()
{
var Flag=false;
for (Var i=0;i<=document.form1.fruit.length-1;i++)
{
if (Form1. fruit[i].checked) {
Flag=true;}
}
if (flag)
{
Alert ("^_^");
return false;
}else{
Alert ("Warrior, you always choose a bar!") ");
}
}
</script>
The end of the radio, flying the boss will not give up, in the evening when a check box for the code.
Copy Code code as follows:
<script>
var j=document.getelementsbyname ("Fruit");
function Allche () {
for (Var i=0 i <j.length; i++) {
if (document.form1.fruit[i].checked!=true) document.form1.fruit[i].checked= document.form1.suoy.checked;
if (document.form1.fruit[i].checked==true) document.form1.fruit[i].checked= document.form1.suoy.checked;
}
}
function Checkall () {
var aa=0
for (Var i=0 i <j.length; i++) {
if (document.form1.fruit[i].checked = = true) aa++;
Aa!=j.length? Document.form1.suoy.checked=false:document.form1.suoy.checked=true;
}
}
function Checkradio () {
var a=0
var list= ""
for (var i=0; i<j.length;i++)
if (document.form1.fruit[i].checked== true) {
list== ""? List=document.form1.fruit[i].value:list=list+ "," +document.form1.fruit[i].value;
}
if (list!= "") Alert ("You like the fruit is" +list);
else{
a++;
if (a==j.length) alert ("eldest brother.") How do I know what you like if you don't choose? ");}
}
</script>
<form name= "Form1" id= "frm" >
Your favorite fruit is:<br>.
<input type=checkbox value= "Apple" name= "Fruit" onclick= "Checkall ()" >
Apple
<input type=checkbox value= "banana" name= "Fruit" onclick= "Checkall" () >
Banana
<input type=checkbox value= "Strawberry" name= "Fruit" onclick= "Checkall" () >
Strawberry
<input type=checkbox value= "Pineapple" name= "Fruit" onclick= "Checkall" () >
Pineapple
<input Type=button value= "select" onclick= "Checkradio ()" >
<input type=checkbox onclick= "Allche ()" Name= "Suoy" > select All
</form>
<script language= "javascript" type= "Text/javascript" id= "Commonjs" >
function test ()
{
Fruitlist = "";
For (I=0;i<document.getelementbyid ("frm"). length;i++)
if (document.getElementById ("frm") [i].type== checkbox && document.getElementById ("frm") [i].checked)
Fruitlist + = document.getElementById ("frm") [I].value + "];
if (fruitlist!= "")
Alert ("Your favorite fruit is" +fruitlist);
Else
Alert ("Big Brother.") How do I know what you like if you don't choose? ");
}
</script>
A more concise code, better results for the check code.
Copy Code code as follows:
<script language= "JavaScript" >
<!--Begin
function Checkall () {
for (var j = 1; J <= 9; j +) {
box = eval ("document.checkboxform.c" + j);
if (box.checked = = false) box.checked = true;
}
}
function Uncheckall () {
for (var j = 1; J <= 9; j +) {
box = eval ("document.checkboxform.c" + j);
if (box.checked = = true) box.checked = false;
}
}
function Switchall () {
for (var j = 1; J <= 9; j +) {
box = eval ("document.checkboxform.c" + j);
box.checked =!box.checked;
}
}
End-->
</script>
<body>
<form name=checkboxform>
<input Type=checkbox name=c1>c1<br>
<input Type=checkbox name=c2>c2<br>
<input Type=checkbox name=c3>c3<br>
<input Type=checkbox name=c4>c4<br>
<input Type=checkbox name=c5>c5<br>
<input Type=checkbox name=c6>c6<br>
<input Type=checkbox name=c7>c7<br>
<input Type=checkbox name=c8>c8<br>
<input Type=checkbox name=c9>c9<br>
<br>
<input Type=button value= "Select All" onclick= "Checkall ()" ><br>
<input Type=button value= "Cancel" onclick= "Uncheckall ()" ><br>
<input Type=button value= "onclick=" Switchall () ><br>
</form>