Solved

get radio button vale in array

Posted on 2016-11-01
7
45 Views
Last Modified: 2016-11-15
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
Comment
Question by:Amita Singh
  • 3
  • 3
7 Comments
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 41868031
<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
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 41868032
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
 
LVL 2

Author Comment

by:Amita Singh
ID: 41868093
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 54

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 41868125
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
 
LVL 2

Author Comment

by:Amita Singh
ID: 41887768
No, I have get solution. Thanx
0
 
LVL 2

Author Closing Comment

by:Amita Singh
ID: 41887771
Thanx Julian.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question