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
Displaying
1.
of
2
Display:
1
4
8
12
16
20
40
Uncheck Radio Button
Language:
Javascript
How to check and uncheck Radio Buttons like checkboxes.
<
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
>
Displaying
1.
of
2
Display:
1
4
8
12
16
20
40
1
2
Next
»
Member Login
|
Contact Us