Home
ASP.Net Code Library
ASP Code Library
Javascript Library
SQL Server 2008
Excel Tools
Search Engines
Web Forms
Uncheck Radio Button
Simple Ajax Combo
Home
Javascript Library
Web Forms
Home
Javascript Library
Web Forms
Uncheck Radio Button
Language::
Javascript
How to check and uncheck Radio Buttons like checkboxes.
[show similar options]
<
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
|
Contact Us