Solved

Using Javascript to grab Radio Button Value

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
email validation 9 48
How to check or uncheck a checkbox using the id of the checkbox 2 18
Why is my $_POST not going to results page 10 36
Slush on text 2 11
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…
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.
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…

749 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