Solved

Drop down & Radio buttons

Posted on 2003-11-25
6
742 Views
Last Modified: 2010-04-09
Hi,
     I am a small problem in HTML.
     I am a radio button & when one checks that button, he is supposed to enter some data from 3 drop down boxes & then proceed.
     But my requirement is such that unless that radio button is checked, the dropdown box is inactive, meaning the no data in the drop down can be viewed or selected. Only when the radio buttons r selected are the drop down data available for viewing & selection.
     Can anyone suggest a way out !
0
Comment
Question by:medebayan
[X]
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
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:xabi
ID: 9823128
What about this?

<html>
<head>
<title>Sample</title>
</head>
<body>
<form name="myform">
<input type="checkbox" name="mycheck" onclick="this.form.myselect.disabled=!this.checked"><br>
<select name="myselect" disabled>
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
</select>
</form>
</body>
</html>

xabi
0
 

Author Comment

by:medebayan
ID: 9823211
I don't think this will solve my problem.
Firstly, there r 2 RADIO BUTTONS. One when selected needs inputs from drop downs, which are populated from the database.
Now, mayb u can provide me with an accurate solution !
0
 
LVL 7

Expert Comment

by:gam3r_3xtr3m3
ID: 9823613
dynamically, here's a solution:

<script language="JavaScript" type="text/javascript">
function enableSelect(){
if(document.theform.selectbox.disabled=true){
document.theform.selectbox.disabled=false;}}
</script>
<body>
<form name="theform">
<input type="radio" onClick="enableSelect();" name="radio1" value="Selection #2">Selection #1<br />
<input type="radio" onClick="enableSelect();" name="radio1" value="Selection #2">Selection #2<br />
<select name="selectbox" disabled="disabled">
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
</select>
</body>
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Accepted Solution

by:
gam3r_3xtr3m3 earned 70 total points
ID: 9823676
OR if your doing a confirmation dynamically like this...:

<html>
<head>
<title>2 radio buttons and a checkbox!</title>
<script language="JavaScript" type="text/javascript">
function checkStat(){
if(document.theform.radio1.checked="undefined"){
alert("Please select a choice!"); return false;}}
function enableSelect(){
if(document.theform.selectbox.disabled=true){
document.theform.selectbox.disabled=false;}
if(document.theform.sbmtbtn.disabled=true){
document.theform.sbmtbtn.disabled=false;}}
function disableSelect(){document.theform.selectbox.disabled=true;}
</script>
</head>
<body>
<div align="center">
<form name="theform" onSubmit="return checkStat();">
<input type="radio" onClick="enableSelect();" name="radio1" value="y" />Add to Database<br />
<input type="radio" onClick="disableSelect();" name="radio1" value="n" />Don't do anything<br />
<select name="selectbox" disabled="disabled">
<option value="1">option 1</option>
<option value="2">option 2</option>
<option value="3">option 3</option>
</select>
<br /><input type="submit" name="sbmtbtn" value="submit" disabled="disabled" />
</div>
</body>
</html>
0
 
LVL 7

Expert Comment

by:gam3r_3xtr3m3
ID: 9823710
lol... i got the title wrong, the coding wrong and i forgot to take of my test checkStat(); function. Too much VB for me. lol... here's mabye a set of all you need:

<html>
<head>
<title>2 radio buttons and a option box!</title>
<script language="JavaScript" type="text/javascript">
var cont1=null;
function loadStat(){
if(document.theform.radio1.selected==true){enableSelect();}}
function checkStat(){
if(cont1=="y"){
alert("Select a database!");return false;}}
function enableSelect(){
cont1="y";
if(document.theform.selectbox.disabled==true){
document.theform.selectbox.disabled=false;}
if(document.theform.sbmtbtn.disabled==true){
document.theform.sbmtbtn.disabled=false;}}
function disableSelect(){
cont1="n";
if(document.theform.selectbox.disabled==false){
document.theform.selectbox.disabled=true;}
if(document.theform.sbmtbtn.disabled==true){
document.theform.sbmtbtn.disabled=false;}}
</script>
</head>
<body onLoad="loadStat();">
<div align="center">
<form name="theform" onSubmit="return checkStat();">
<input type="radio" onClick="enableSelect();" name="radio1" value="y" />Add to Database<br />
<input type="radio" onClick="disableSelect();" name="radio1" value="n" />Don't do anything<br />
<select name="selectbox" disabled="disabled">
<option>Please select one...</option>
<option value="db1">database 1</option>
<option value="db2">database 2</option>
<option value="db3">database 3</option>
</select>
<br /><input type="submit" name="sbmtbtn" value="Submit" disabled="disabled" />
</div>
</body>
</html>
0
 

Author Comment

by:medebayan
ID: 9823763
Thanx a lot ! This should serve my need..
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

734 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