Solved

Using Javascript to grab Radio Button Value

Posted on 2006-10-25
4
410 Views
Last Modified: 2006-11-18
Very simply, I have two radio buttons:

Single
Double

which represent a "door-type" ( a single door, double door).


When I click one of these buttons, my intention is to toggle a photo. Anyways, I am ALWAYS getting the value "single".


To summarize, the doSwap function is always alerting "single" when in fact, I am clicking 'double'.


Thanks!!



My Javascript:
-----------------
<script language="JavaScript" type="text/javascript">

<!--
      YAHOO.example = function() {

            var $D = YAHOO.util.Dom;
            var $E = YAHOO.util.Event;
            var $A = YAHOO.util.Anim;
            var $M = YAHOO.util.Motion;
            var $DD = YAHOO.util.DD;
            var $ = $D.get;
            
            // Public Variables


                                    
                                    return {
                                    
                                          init : function() {
                                          
                                                // Make sure pics are right
                                                this.resetPics();
                                                
                                                // Attach Events
                                                TODO:
                                                                        
                                                
                                          },
                                          
                                          doSwap : function() {
                                          
                                                // Change the photo
                                                alert($('door_type').value);
                                          
                                          },
                                          
                                          resetPics: function() {
                                          
                                                // Make sure the correct photo is displayed
                                                // TODO
                                          
                                          }
                                    }
                                    
                                                

            
      }();
      
      
      // Fire when available
      YAHOO.util.Event.onAvailable('doc',YAHOO.example.init, YAHOO.example, true);
      
      //-->

</script>



<input onclick="YAHOO.example.doSwap()" id="door_type" name="door_type" type="radio" value="single" <?php
                              if($sel=="single"){
                              echo "checked";
                              }                  
                                                                                    
                                                                                    
                                                                                    ?>>

<input onclick="YAHOO.example.doSwap()" id="door_type" name="door_type" type="radio" value="double" <?php
                              if($sel=="double"){
                              echo "checked";
                              }                                                      
                                                                                    
                                                                                    
                                                                                    ?>>
                                                     
0
Comment
Question by:edvinson
  • 2
  • 2
4 Comments
 
LVL 41

Accepted Solution

by:
HonorGod earned 500 total points
ID: 17807111
<html>
<head>
<title>Radio Button value</title>
<script type='text/javascript'>
  function ShowInfo( obj ) {
    var text = obj.nextSibling.nodeValue;
    alert( 'Selection: id = "' + obj.id + '"  value = "' + text + '"' );
  }
</script>
</head>
<body>

<table border='1'>
  <tr>
    <td><input id='Yes'   type='radio' name='RB' onclick='ShowInfo(this)' value='1'> Yes</input></td>
  </tr>
  <tr>
    <td><input id='No'    type='radio' name='RB' onclick='ShowInfo(this)' value='0'> No</input></td>
  </tr>
  <tr>
    <td><input id='Maybe' type='radio' name='RB' onclick='ShowInfo(this)' value='-1'> Maybe</input></td>
  </tr>
</table>

</body>
</html>
0
 
LVL 1

Author Comment

by:edvinson
ID: 17807146
I am getting this:

Selection: id = "door_type" value = " "

0
 
LVL 1

Author Comment

by:edvinson
ID: 17807235
NM... I got it. Silly me was using the same id for both.

You get the points for trying. :)
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 17807339
Thanks for the 'A'
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

867 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

19 Experts available now in Live!

Get 1:1 Help Now