.







Cenk Yurtseven
 
English Deutsch Türkçe
Home Javascript Library Javascript Library Web Forms Web Forms

 
Uncheck Radio Button Uncheck Radio Button Dili:  Javascript 
How to check and uncheck Radio Buttons like checkboxes.

Uncheck Radio Button

<SCRIPT TYPE="text/javascript">
var isChecked = false;
var lastRadio = null;
var lastField = null;
function cy(theField)
{
var objForm = document.forms[0];
if (theField == lastField)
{
for(var i = 0; i < theField.length; i++)
{
if (objForm.elements[theField][i].checked == true && isChecked && lastRadio == i)
{
objForm.elements[theField][i].checked = false;
isChecked = false;
lastRadio = i;
break;
}
else if (objForm.elements[theField][i].checked == true)
{
objForm.elements[theField][i].checked = true;
isChecked = true;
lastRadio = i;
break;
}
}
}
else
{
lastField = theField;
for(var i = 0; i < theField.length; i++)
{
if (objForm.elements[theField][i].checked == true)
{
objForm.elements[theField][i].checked = true;
isChecked = true;
lastRadio = i;
break;
}
}
}
}
</
SCRIPT>
<
FORM NAME="myForm">
1: <INPUT TYPE="radio" NAME="myField" onclick="cy('myField');">
<INPUT TYPE="radio" NAME="myField" onclick="cy('myField');">
<INPUT TYPE="radio" NAME="myField" onclick="cy('myField');">
<hr>
2: <INPUT TYPE="radio" NAME="myField2" onclick="cy('myField2');">
<INPUT TYPE="radio" NAME="myField2" onclick="cy('myField2');">
<INPUT TYPE="radio" NAME="myField2" onclick="cy('myField2');">
</
FORM>


Member Login  |  Kontakt