Solved

get radio button vale in array

Posted on 2016-11-01
7
50 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 57

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 57

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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
LVL 57

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Passing ASP variables in JQuery 4 52
How can I do this in Angular, instead of jQuery? 2 22
How does this modal gets closed? 6 41
Jquery syntax 12 29
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
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.

738 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