Solved

get radio button vale in array

Posted on 2016-11-01
7
37 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 51

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 51

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 51

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now