Solved

Using Javascript to grab Radio Button Value

Posted on 2006-10-25
4
409 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

707 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

16 Experts available now in Live!

Get 1:1 Help Now