Solved

Help javascript radio button

Posted on 2014-04-07
4
491 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
[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
 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

730 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