Solved

Javascript onselect from drop down box

Posted on 2007-11-13
3
19,408 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article discusses how to create an extensible mechanism for linked drop downs.
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

920 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

12 Experts available now in Live!

Get 1:1 Help Now