Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CheckBox

22 views
Skip to first unread message

java...@gmail.com

unread,
May 24, 2007, 4:27:05 AM5/24/07
to
HI


how to select only one check box in two checkboxes like radio buttons

Darko

unread,
May 24, 2007, 12:31:10 PM5/24/07
to
On May 24, 10:27 am, java.i...@gmail.com wrote:
> HI
>
> how to select only one check box in two checkboxes like radio buttons

Take a book on Javascript and English language, syntax and grammar,
then try it again and if you don't succeed, then come back here and
ask the question again, but with more details on what your problem is
(not only what you want to do even if you haven't tried it yourself)

Evertjan.

unread,
May 24, 2007, 12:56:38 PM5/24/07
to

The OP could be right:

That one in two checkboxes do like radio buttons.

Don't you love them?

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Jeff Johns

unread,
May 24, 2007, 4:39:41 PM5/24/07
to
On May 24, 12:56 pm, "Evertjan." <exjxw.hannivo...@interxnl.net>
wrote:

HTML
<input type="checkbox" name="test" id="test" value="1"
onclick="check_it(this);" />
<input type="checkbox" name="test" id="test1" value="2"
onclick="check_it(this);" />

SCRIPT
function check_it(obj)
{
if (this.id == 'test' && this.checked) {
document.getElementById('test1').checked = false;
}
elseif (this.id == 'test1' && this.checked) {
document.getElementById('test').checked = false;
}
}

This is just a very simple way to do it.

-Lost

unread,
May 24, 2007, 5:43:21 PM5/24/07
to
Jeff Johns wrote:

> HTML
> <input type="checkbox" name="test" id="test" value="1"
> onclick="check_it(this);" />
> <input type="checkbox" name="test" id="test1" value="2"
> onclick="check_it(this);" />
>
> SCRIPT
> function check_it(obj)
> {
> if (this.id == 'test' && this.checked) {
> document.getElementById('test1').checked = false;
> }
> elseif (this.id == 'test1' && this.checked) {
> document.getElementById('test').checked = false;
> }
> }
>
> This is just a very simple way to do it.

Too bad it doesn't work as is.

All instances of "this" in your "SCRIPT" block should be "obj".

Also, there is no such thing as an "elseif" in JavaScript. You meant
"else if".

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.

Jeff Johns

unread,
May 25, 2007, 11:10:05 AM5/25/07
to

Indeed, sorry for the confusion.

Here this works:

SCRIPT
function check_it(obj)
{
if (obj.id == 'test' && obj.checked) {


document.getElementById('test1').checked = false;
}

else if (obj.id == 'test1' && obj.checked) {

0 new messages