smphil
asked on
How do you disable a select menu
How can I disable the country select menu if anything but USA is chosen?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Select Menu Help</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form1" method="post" action="">
<select name="country" id="country">
<option>Country</option>
<option value="USA">USA</option>
<option value="All other countries">All other countries</option>
<option value="All other countries">All other countries</option>
<option value="All other countries">All other countries</option>
</select>
<select name="state" id="state">
</select>
<select name="sex" id="sex">
</select>
</form>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Select Menu Help</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form1" method="post" action="">
<select name="country" id="country">
<option>Country</option>
<option value="USA">USA</option>
<option value="All other countries">All other countries</option>
<option value="All other countries">All other countries</option>
<option value="All other countries">All other countries</option>
</select>
<select name="state" id="state">
</select>
<select name="sex" id="sex">
</select>
</form>
</body>
</html>
If you want to disable All other countries other than USA, what'd be the purpose of displaying All other countries!?
If you meant disabling "state" if other coutry is selected, you could use this:
onchange="if (this.options[this.selecte dIndex].va lue!='USA' ) this.form.state.disabled=t rue; else this.form.state.disabled=f alse;"
If you meant disabling "state" if other coutry is selected, you could use this:
onchange="if (this.options[this.selecte
ASKER
Thats it jags if any other country but usa is selected I want the state disabled
ASKER
What happens to the value of the state when its disabled can I have it default to say "Not In the USA"
So say they screw with the state first then choose a different coutry can it be disabled to a default like "Not IN USA"
So say they screw with the state first then choose a different coutry can it be disabled to a default like "Not IN USA"
When you disable a <select name="state"> menu and submit the page, and in the next page if you try to retrieve it with request.getParameter("stat e"); it will not give you any value.
The first page might show you some default option value "Select State" in the select state drop down [though disabled], it will not be passed to the next page. You will always end up getting "null" value for request.getParameter("stat e");
If you want it to pass a default value "NotInUSA" you have no other go but to enable the state with the option value set to "NotInUSA" and submit it. i.e., just onClick of submit button, call a javascript and write the code to enable the state select menu and submit the page. This way user will feel for a glance of minute before submitting the value selected as "NotInUSA".
jsp1.jsp
-----
<html>
<head>
<script language="JavaScript">
function submit()
{
if(document.jsp1form.state .disabled= =true)
{
document.jsp1form.state.di sabled = false;
document.jsp1form.state.op tions[this .selectedI ndex].valu e = 'NotInUSA';
}
document.jsp1form.src = "jsp2page.jsp";
document.jsp1form.submit() ;
}
</script>
</head>
<body>
<form name=jsp1form>
<select name="country" id="country" onchange="if (this.options[this.selecte dIndex].va lue!='USA' ) this.form.state.disabled=t rue; else this.form.state.disabled=f alse;">
<option>Country</option>
<option value="USA">USA</option>
<option value="All other countries">All other countries</option>
<option value="All other countries">All other countries</option>
<option value="All other countries">All other countries</option>
</select>
<select name="state" id="state">
</select>
<select name="sex" id="sex">
</select>
<input type=button value="submit" onClick="javascript:submit ()">
</form>
</body>
</html>
Hope this should answer !!
(Tip: just onclick of submitting, enable the state that is disabled to send it as a parameter, other wise it wont be passed to the next page)
The first page might show you some default option value "Select State" in the select state drop down [though disabled], it will not be passed to the next page. You will always end up getting "null" value for request.getParameter("stat
If you want it to pass a default value "NotInUSA" you have no other go but to enable the state with the option value set to "NotInUSA" and submit it. i.e., just onClick of submit button, call a javascript and write the code to enable the state select menu and submit the page. This way user will feel for a glance of minute before submitting the value selected as "NotInUSA".
jsp1.jsp
-----
<html>
<head>
<script language="JavaScript">
function submit()
{
if(document.jsp1form.state
{
document.jsp1form.state.di
document.jsp1form.state.op
}
document.jsp1form.src = "jsp2page.jsp";
document.jsp1form.submit()
}
</script>
</head>
<body>
<form name=jsp1form>
<select name="country" id="country" onchange="if (this.options[this.selecte
<option>Country</option>
<option value="USA">USA</option>
<option value="All other countries">All other countries</option>
<option value="All other countries">All other countries</option>
<option value="All other countries">All other countries</option>
</select>
<select name="state" id="state">
</select>
<select name="sex" id="sex">
</select>
<input type=button value="submit" onClick="javascript:submit
</form>
</body>
</html>
Hope this should answer !!
(Tip: just onclick of submitting, enable the state that is disabled to send it as a parameter, other wise it wont be passed to the next page)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Select Menu Help</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="form1" method="post" action="">
<select name="country" id="country" onchange="if (this.options[this.selecte
<option>Country</option>
<option value="USA">USA</option>
<option value="All other countries">All other countries</option>
<option value="All other countries">All other countries</option>
<option value="All other countries">All other countries</option>
</select>
<select name="state" id="state">
</select>
<select name="sex" id="sex">
</select>
</form>
</body>
</html>
Cd&