Solved

get radio button vale in array

Posted on 2016-11-01
7
54 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 58

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 58

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
Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

 
LVL 58

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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)

617 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