<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script>
function combosetdefault()
{
var x = "Delhi";
document.getElementById("state1").value = x;
}
</script>
</head>
<body>
<table>
<tr>
<td>State</td>
<td>:</td>
<td>
<select style="padding:2px; border-radius:4px" name="state" id="state1">
<option value="Chennai" >Chennai</option>
<option value="Kolkata">Kolkata</option>
<option value="Uttar Predesh">Uttar Predesh</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" value="SetDefault" onclick=
"combosetdefault()">
</td>
</tr>
</table>
</body>
</html>
Example : How to show/hide text box on choosing Yes or No choice from a combo box using Java Script.
<!DOCTYPE html>
<html>
<head>
<title>Codershelpline</title>
<script>
function showhide()
{
var x=document.getElementById("sh2").value;
if(x==="Yes")
{
document.getElementById("txtbox2").style.display='block';
}
else
{
document.getElementById("txtbox2").style.display="none";
}
}
</script>
</head>
<body>
<form>
<table>
<tr>
<td>Any Disability</td>
<td>:</td>
<td>
<select name="sh1" id="sh2" onchange="showhide()">
<option value="Select One">Select Only</option>
<option value="No">No</option>
<option value="Yes">Yes</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td></td>
<td>
<input type="text" name="txtbox1" id="txtbox2" style="display: none">
</td>
</tr>
</table>
</form>
</body>
</html>
0 Comments