Solved

Using Javascript to grab Radio Button Value

Posted on 2006-10-25
4
416 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
[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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

690 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