Solved

Using Javascript to grab Radio Button Value

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

829 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