• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 974
  • Last Modified:

dynamic radio button default state via change of selected index

I need to be able to change the selected state of a radio button named "price_type" when a  user selects a certain value from a drop down menu item. For example if the user chooses "services" for the drop down menu the radio buttons appear as "per hour", and "total" with total selected as default.... but if the user chooses "housing" from the same drop down menu, the radio options are now "per month", and "per semester" with per month selected  as default.

I have already gotten the correct radio buttons to appear when the menu item is selected, but i need to be able to change the state of the defaulted selection to help validate the form.

Thanks fir any help.
0
digiblis
Asked:
digiblis
  • 3
  • 3
1 Solution
 
Russell2566Commented:
Like this?

<html>
<head>
      <script>
            function changeService() {
                  form = document.forms['form1'];
                  selA = form.selA;
                  radio1 = form.radio1;

                  if (selA.options[selA.selectedIndex].value == "Option 1") {
                        radio1[0].value = "Per Hour"
                        radio1[1].value = "Total"
                  } else if (selA.options[selA.selectedIndex].value == "Option 2") {
                        radio1[0].value = "Per Month"
                        radio1[1].value = "Per Semester"
                  }
                  

                  document.getElementById("radio1Desc1").innerHTML = radio1[0].value;
                  document.getElementById("radio1Desc2").innerHTML = radio1[1].value;
            }
      </script>

</head>

<body>

      <form name="form1">
            <select name="selA" onChange="changeService();">
                  <option value="Option 1">Option 1</option>
                  <option value="Option 2">Option 2</option>
            </select>

            <input type="checkbox" name="radio1" value="Per Hour"> <span id="radio1Desc1">Per Hour</span>
            <input type="checkbox" name="radio1" value="Total"> <span id="radio1Desc2">Total</span>
      </form>

</body>

</html>
0
 
digiblisAuthor Commented:
kind of.. but i needed to use radio button because i wanted only one selection made. I'll try it with a radio button with the same code, and just replace the check box you had.
0
 
Russell2566Commented:
woops, sorry... all you have to do is change the type...
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
digiblisAuthor Commented:
How would you change the selected state for the radio button?

something like?

if (selA.options[selA.selectedIndex].value == "Option 1") {
                        radio1[0].selected = "yes"
                       
                  } else if (selA.options[selA.selectedIndex].value == "Option 2") {
                       radio1[0].selected = "yes"
                     
                  }


-------------

i realize you probably cant use the selected - "yes", but i want to be able to change the selected state depending on the option selected from the drop down menu. Thanks again.
0
 
Russell2566Commented:
.checked = true
0
 
digiblisAuthor Commented:
sweet thanks!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now