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
Solved

Help javascript radio button

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 109
Powershell Script need assistance to make some changes 4 91
Bartender label printing - switch on and off graphics 3 54
Problem to App 4 97
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
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.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

840 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