moody
moody

Reputation: 402

checkboxes behave like radiobuttons with different names

i have a problem, which might be easy for you guys. Im new in jquery and trying to do a form (calculator) of selectboxes, checkboxes and 3 radiobuttons (with 3 same names, just one or none can be checkable).

When i submit the form (at the first time), the values of each inputs stay the same as I wanted to. But when I submit it the second time without refreshing/resetting, the radiobutton which was checked before disappears and even when I reclick a radiobutton without refreshing and submit it, the value cant maintained by php.

So I decided to change the radio buttons to checkboxes, and that is where I need your help.

I need 3 checkboxes which can be selected just one or none of them with different "names".

<input type="checkbox" id="checkbox8" value="1" name="8" <?php if(isset($_POST['8']) && $_POST['8'] == '1') echo 'checked="checked"';?> />
<input type="checkbox" id="checkbox9" value="2" name="9" <?php if(isset($_POST['9']) && $_POST['9'] == '2') echo 'checked="checked" ';?> />
<input type="checkbox" id="checkbox10" value="3" name="10" <?php if(isset($_POST['10']) && $_POST['10'] == '3') echo 'checked="checked" ';?> />

I prepared this:

[a link] (http://jsfiddle.net/ry4k8ve9/)

thanks a lot in advance!! Hope you can help me

Upvotes: 0

Views: 73

Answers (2)

Umesh Sehta
Umesh Sehta

Reputation: 10683

try this:-

var $unique = $('#checkbox8,#checkbox9,#checkbox10');
$unique.click(function() {
   $unique.not(this).removeAttr('checked');    
});

Demo

Upvotes: 0

Anduril
Anduril

Reputation: 1276

Just add a click event to your checkboxes to turn the others off:

$('input[type="checkbox"]').click(function(){
    $('input[type="checkbox"]').not(this).prop('checked', false)
})

Upvotes: 1

Related Questions