Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 58
  • Last Modified:

get radio button vale in array

this div append dynamically. i want the radio button value.

<div class="form-group">
                  <label class="col-md-3">Course Type <span style="color:#F00;">*</span></label>
                  <div class="col-md-9"> <span class="col-md-2">
                    <input name="course[]" type="radio" value="Full Time" required> &nbsp; Full Time</span> <span class="col-md-2">
                    <input name="course[]" type="radio" value="Part Time" required>&nbsp; Part Time</span> <span class="col-md-3">
                    <input name="course[]" type="radio" value="Correspondence" required>&nbsp; Correspondence</span> </div>
                </div>
                <br>
                <div class="form-group">
                  <label class="col-md-3">Course Type <span style="color:#F00;">*</span></label>
                  <div class="col-md-9"> <span class="col-md-2">
                    <input name="course[]" type="radio" value="Full Time" required> &nbsp; Full Time</span> <span class="col-md-2">
                    <input name="course[]" type="radio" value="Part Time" required>&nbsp; Part Time</span> <span class="col-md-3">
                    <input name="course[]" type="radio" value="Correspondence" required>&nbsp; Correspondence</span> </div>
                </div><br>
                <div class="form-group">
                  <label class="col-md-3">Course Type <span style="color:#F00;">*</span></label>
                  <div class="col-md-9"> <span class="col-md-2">
                    <input name="course[]" type="radio" value="Full Time" required> &nbsp; Full Time</span> <span class="col-md-2">
                    <input name="course[]" type="radio" value="Part Time" required>&nbsp; Part Time</span> <span class="col-md-3">
                    <input name="course[]" type="radio" value="Correspondence" required>&nbsp; Correspondence</span> </div>
                </div><br>
                <div class="form-group">
                  <label class="col-md-3">Course Type <span style="color:#F00;">*</span></label>
                  <div class="col-md-9"> <span class="col-md-2">
                    <input name="course[]" type="radio" value="Full Time" required> &nbsp; Full Time</span> <span class="col-md-2">
                    <input name="course[]" type="radio" value="Part Time" required>&nbsp; Part Time</span> <span class="col-md-3">
                    <input name="course[]" type="radio" value="Correspondence" required>&nbsp; Correspondence</span> </div>
                </div>
                

Open in new window

0
Amita Singh
Asked:
Amita Singh
  • 3
  • 3
1 Solution
 
Julian HansenCommented:
<script>
$(function() {
  // To get the value on click (for dynamic content)      
  $('body').on('click',':radio', function() {
     var value = $(this).val();
  });

  // To get the value of the selected radio after content loaded
  $('button').click(function() {
    var value = $(':radio[name="course[]"]:checked').val();
  });
});
</script>

Open in new window

Working sample here
1
 
Julian HansenCommented:
If you have different radio's on the page and you want to single out only the course[] ones then
<script>
$(function() {
  // To get the value on click (for dynamic content)      
  $('body').on('click',':radio[name="course[]"]', function() {
     var value = $(this).val();
  });

  // To get the value of the selected radio after content loaded
  $('button').click(function() {
    var value = $(':radio[name="course[]"]:checked').val();
  });
});
</script>

Open in new window

0
 
Amita SinghWeb DeveloperAuthor Commented:
Thanx for reply julian,

in your example you repeat div in 4 times. i want i check radio button 4 times.
ex. first div radio button i check full time.  2nd div i check part time than 3rd div i check again full time.

in the current example i check only one radio button but i need check one radio button in every row.

1.png
Sorry my poor english.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Julian HansenCommented:
Your radio buttons are all named the same - so they will be part of the same group. If you need to break them up then you need to give them different names.

Currently the name is "course[]" - this will need to change to something unique per group something like
course[group1] for the first div course[group2] for the first div.

First resolve that then we can take it forward.
0
 
Amita SinghWeb DeveloperAuthor Commented:
No, I have get solution. Thanx
0
 
Amita SinghWeb DeveloperAuthor Commented:
Thanx Julian.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now