6 Replies - 1182 Views - Last Post: 21 November 2015 - 08:29 AM

#1 dardime   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 09-February 11

Select All Radio Buttons

Posted 28 October 2015 - 01:58 PM

Hi there i need to select all radio buttons using jquery in one click but it can select only 2 times and it wont work after. I need to work every time i select.

my code:
<script type="text/javascript">

  $(document).ready(function(){
	
    $("#selectPass").click(function () {
		
	$('input:radio[value=pass]').attr('checked',true);
	//$('input:radio[value=pass]').checked = true;

    });
	
    $("#selectNone").click(function () {
		
	$('input:radio[value=none]').attr('checked',true);
	//$('input:radio[value=none]').checked = true;
			
    });
		
  });
</script>


my Code:
<tr>
                                            <th><strong>Item</strong></th>
                                            <th><strong>Pass</strong> <input type='button' value='Select All' class="btn btn-primary btn-xs" id='selectPass'></th>
                                            <th><strong>Fail</strong></th>
                                            <th><strong>N/A</strong> <input type='button' value='Select All' class="btn btn-primary btn-xs" id='selectNone'></th>
                                        </tr>


Thanks in advance for your help.

This post has been edited by dardime: 28 October 2015 - 02:01 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Select All Radio Buttons

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4217
  • View blog
  • Posts: 13,328
  • Joined: 08-June 10

Re: Select All Radio Buttons

Posted 28 October 2015 - 02:01 PM

what is the setup of the radio buttons?
Was This Post Helpful? 0
  • +
  • -

#3 dardime   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 09-February 11

Re: Select All Radio Buttons

Posted 28 October 2015 - 02:04 PM

<tr>
                                            <td>LCD Touch screen</td>
                                            <td>
                                            	<input name="lcd" type="radio" id="lcd" value="pass" <?php if(!empty($_POST["lcd"]) && !empty($error) && $_POST["lcd"] == "pass") { echo "checked"; } else { if($qcs[0]["lcd"] == "pass") { echo "checked"; } } ?>>
                                            </td>
                                            <td>
                                            	<div style="float:left"><input name="lcd" type="radio" id="lcd" value="fail" <?php if(!empty($_POST["lcd"]) && !empty($error) && $_POST["lcd"] == "fail") { echo "checked"; } else { if($qcs[0]["lcd"] == "fail") { echo "checked"; } } ?>></div>
                                                <div style="float:left; padding-left:10px;"><input name="lcd_details" class="form-control" type="text" id="lcd_details" placeholder="Enter lcd details" value="<?php if(!empty($_POST["lcd_details"]) && !empty($error)) { echo $_POST["lcd_details"]; } ?>"></div>
                                            </td>
                                            <td>
                                            	<input name="lcd" type="radio" id="lcd" value="none" <?php if(!empty($_POST["lcd"]) && !empty($error) && $_POST["lcd"] == "none") { echo "checked"; } else { if($qcs[0]["lcd"] == "none") { echo "checked"; } } ?>>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>Mic</td>
                                            <td>
                                            	<input name="mic" type="radio" id="mic" value="pass" <?php if(!empty($_POST["mic"]) && !empty($error) && $_POST["mic"] == "pass") { echo "checked"; } else { if($qcs[0]["mic"] == "pass") { echo "checked"; } } ?>>
                                            </td>
                                            <td>
                                            	<div style="float:left"><input name="mic" type="radio" id="mic" value="fail" <?php if(!empty($_POST["mic"]) && !empty($error) && $_POST["mic"] == "fail") { echo "checked"; } else { if($qcs[0]["mic"] == "fail") { echo "checked"; } } ?>></div>
                                                <div style="float:left; padding-left:10px;"><input name="mic_details" class="form-control" type="text" id="mic_details" placeholder="Enter mic details" value="<?php if(!empty($_POST["mic_details"]) && !empty($error)) { echo $_POST["mic_details"]; } ?>"></div>
                                            </td>
                                            <td>
                                            	<input name="mic" type="radio" id="mic" value="none" <?php if(!empty($_POST["mic"]) && !empty($error) && $_POST["mic"] == "none") { echo "checked"; } else { if($qcs[0]["mic"] == "none") { echo "checked"; } } ?>>
                                            </td>
                                        </tr>


It is setup on the above code. it works but it will work 2 times and i want it work all time. Thanks for your quick reply
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4217
  • View blog
  • Posts: 13,328
  • Joined: 08-June 10

Re: Select All Radio Buttons

Posted 28 October 2015 - 02:13 PM

change attr() to prop().
Was This Post Helpful? 0
  • +
  • -

#5 dardime   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 55
  • Joined: 09-February 11

Re: Select All Radio Buttons

Posted 28 October 2015 - 02:19 PM

WOW thats wonderful. it works now! Thank you so much for your quick help. :D
Was This Post Helpful? 0
  • +
  • -

#6 ArtificialSoldier   User is online

  • D.I.C Lover
  • member icon

Reputation: 2104
  • View blog
  • Posts: 6,443
  • Joined: 15-January 14

Re: Select All Radio Buttons

Posted 28 October 2015 - 04:03 PM

Also, you've got several radio buttons with the same IDs there, IDs should be unique on each page.
Was This Post Helpful? 0
  • +
  • -

#7 blankwavercade   User is offline

  • D.I.C Head

Reputation: 31
  • View blog
  • Posts: 123
  • Joined: 13-December 11

Re: Select All Radio Buttons

Posted 21 November 2015 - 08:29 AM

Sorry for posting a month old post. However you shouldn't be using radio buttons if you want to select all of them. You should change the radio buttons to check boxes. Radio buttons are used for a single selection, for instance a yes or no option.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1