Solved

Javascript onselect from drop down box

Posted on 2007-11-13
3
19,406 Views
Last Modified: 2012-06-27
I have a drop down box ...
When the enduser selects something from this box, I need the focus to go to two radio buttons and require them to choose one of them...

and I need the radio buttons inactive UNTIL someone is selected from drop down...

Possible?
0
Comment
Question by:tsmithinnc
3 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 20275404
Show your html that you have so far.

0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 20275444
something like this
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
      <title>Untitled</title>
</head>

<body>
<select name="mySelect" id="mySelect" onChange="if(this.options[this.selectedIndex].value=='show'){document.getElementById('myFieldSet').style.visibility='visible'}else{document.getElementById('myFieldSet').style.visibility='hidden'}">
<option value="">Select</option>
<option value="show">Show</option>
<option value="hide">Hide</option>

</select><br>


<fieldset id="myFieldSet" style="border:1px solid grey; width:50%; visibility:hidden">
<legend>Select Option</legend>
<input type="radio" name="myRadio" value="0">Option 1<br>
<input type="radio" name="myRadio" value="1">Option 2<br>
<input type="radio" name="myRadio" value="2">Option 3<br>
<input type="radio" name="myRadio" value="3">Option 4<br>
</fieldset>


</body>
</html>
0
 
LVL 12

Accepted Solution

by:
netsmithcentral earned 500 total points
ID: 20275516
Try this:

<html>
<head>
<script type="text/javascript">
<!--
function selChk(obj) {
      if(obj.value!='nosel') {
            var rs = document.getElementsByName('rad');
            for(i=0; i<rs.length; i++){
                  rs[i].disabled = false;
            }
            if(rs.length>0) rs[0].focus();
      } else {
            var rs = document.getElementsByName('rad');
            for(i=0; i<rs.length; i++){
                  rs[i].disabled = true;
                  rs[i].checked = false;
                  rs[i].blur();
            }
      }
}

function frmChk(){
      var rs = document.getElementsByName('rad');
      var chk = false;
      for(i=0; i<rs.length; i++){
            if(rs[i].checked) return true;
      }
      
      alert('You must select one of the choices!');
      return false;
}
//-->
</script>
</head>
<body>
<form onsubmit="return frmChk();">
The Select Box:
<select id="sel" onchange="selChk(this);">
      <option selected value="nosel">Select A Value
      <option value="val">Value
      <option value="val2">Value 2
</select>
<br><br>
The Radio Buttons:<br>
<input type="radio" name="rad" disabled> Choice 1&nbsp;&nbsp;<input type="radio" name="rad" disabled> Choice 2
<br><br>
The Submit Button: <input type="submit" value="Submit!">
</form>
</body>
</html>
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 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

22 Experts available now in Live!

Get 1:1 Help Now