?
Solved

Help javascript radio button

Posted on 2014-04-07
4
Medium Priority
?
508 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

777 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