0

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

Jonas
  • 121,568
  • 97
  • 310
  • 388
moody
  • 404
  • 7
  • 19
  • 1
    http://stackoverflow.com/questions/881166/jquery-checkboxes-like-radiobuttons – Umesh Sehta Oct 17 '14 at 11:42
  • http://jsfiddle.net/ry4k8ve9/2/ – Umesh Sehta Oct 17 '14 at 11:45
  • hey mohit, thanks for the fast answer. the problem is, that I have 10 checkboxes in total, and only checkbox8, checkbox9 and checkbox10 should behave like requested. How can I do this then? – moody Oct 17 '14 at 13:05
  • I got it. I just put them in a div with ID :) – moody Oct 17 '14 at 13:15
  • when I wrap them in a div with id and call by $('#testing input[type="checkbox"]'); in jfiddle it works, in my program its not working. where do I put the code, in $(document)ready(function() {... ?? – moody Oct 17 '14 at 13:46
  • Yes you need to wrap under document ready function or you can check browser console for other error – Umesh Sehta Oct 17 '14 at 14:05

2 Answers2

1

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)
})
Anduril
  • 1,236
  • 1
  • 9
  • 33
0

try this:-

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

Demo

Umesh Sehta
  • 10,555
  • 5
  • 39
  • 68