[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Javascript onselect from drop down box

Posted on 2007-11-13
3
Medium Priority
?
19,437 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 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This article discusses how to create an extensible mechanism for linked drop downs.
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 invoke it on a web page. 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.: (CODE)
Suggested Courses
Course of the Month19 days, 19 hours left to enroll

872 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