Solved

Help javascript radio button

Posted on 2014-04-07
4
479 Views
Last Modified: 2014-04-08
Javascript - can a radio button options dependent on other radio button choices? My javascript below show no changes  


<script type="text/javascript">

      function setshowName(passvar)
      {
      
             
            if ( passvar == 'T')
            {
                  document.getElementById('showName').value = "yes";
                        }
            else
            {

                  document.getElementById('showName').value = "no";
                  
            }
      
      }
</script>





<form name="testform" method="post">
<table>
  <tr>
      <td>
      Show Address:
        <INPUT TYPE="RADIO" NAME="showaddr" VALUE="A" onclick="setshowName('A')" checked>Show A Address
      <INPUT TYPE="RADIO" NAME="showaddr" VALUE="B" onclick="setshowName('B')">Show B Address
      </td>
  </tr>
  <tr>
      <td>
        Show Test Name:
        <INPUT TYPE="RADIO" NAME="showName" VALUE="yes" checked>yes
        <INPUT TYPE="RADIO" NAME="showName" VALUE="no">no
     </td>
   </tr>
</table>
</form>
0
Comment
Question by:jfreeman2010
  • 2
  • 2
4 Comments
 

Author Comment

by:jfreeman2010
ID: 39984634
I want to make the JavaScript will do:

When click on Show A Address, show test name will checked 'yes',
when click on Show B Address, show test name will checked 'no'

Thank you
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 39984642
It doesn't work that way.  In addition, you didn't have 'id's for the 'showname' radio buttons.  Try this instead.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Untitled</title>
<script type="text/javascript">

      function setshowName(passvar)
      {
      
             
            if ( passvar == 'A')
            {
                  document.getElementById('showName1').checked = true;
                  document.getElementById('showName2').checked = false;
                        }
            if ( passvar == 'B')
            {

                  document.getElementById('showName1').checked = false;
                  document.getElementById('showName2').checked = true;
                  
            }
      
      }
</script>
</head>
<body>


<form name="testform" method="post">
<table>
  <tr>
      <td>
      Show Address:
      <INPUT TYPE="RADIO" NAME="showaddr" VALUE="A" onclick="setshowName('A')" checked>Show A Address
      <INPUT TYPE="RADIO" NAME="showaddr" VALUE="B" onclick="setshowName('B')">Show B Address
      </td>
  </tr>
  <tr>
      <td>
        Show Test Name:
        <INPUT TYPE="RADIO" NAME="showName" id="showName1" VALUE="yes" checked>yes
        <INPUT TYPE="RADIO" NAME="showName" id="showName2" VALUE="no">no
     </td>
   </tr>
</table>
</form> 
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:jfreeman2010
ID: 39986215
Dave,

Thank you for your help!!  It works.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39986553
You're welcome, glad to help.
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

Suggested Solutions

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

920 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

15 Experts available now in Live!

Get 1:1 Help Now