Click to See Complete Forum and Search --> : dynamic display of combo box in a form


rosy
11-13-2006, 01:41 PM
Hi,
How could i hide a combo box when form loads, and make it appear when an item is selected in a combo box in a form.
please some one help me with code and example.
Thanks

devinemke
11-13-2006, 01:59 PM
<html>
<head>
<script type="text/javascript" language="javascript">
function hide_show_combo()
{
if (document.form.hide_show.selectedIndex == 0) {document.form.combo.style.visibility = "hidden";}
else {document.form.combo.style.visibility = "visible";}
}
</script>
</head>
<body>

<form action="" method="POST" name="form">

<select name="hide_show" size="2" onchange="hide_show_combo();">
<option value="hide">hide</option>
<option value="show">show</option>
</select>

<br>
<br>

<select name="combo" size="3" style="visibility: hidden;">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>

</form>

</body>
</html>

rosy
11-13-2006, 02:35 PM
Thanks a lot!!!!! :-) it works!!!.
Thanks.
I have another issue, how can i display item in a combo box(drop down), based on item selected in another combo box(drop down).
Actually i have items retrieved based on db in combo box.

<TD ><B>combo1:</B></TD>

<select name="step" size="1" class="text" id="step" tabindex="11" onChange="Showitemincombox2(this.form);">\n";
<?php
$selectThis = 0;
$sqlone = mysql_query("SELECT * FROM table1");
while ($sqlonerow = mysql_fetch_array($sqlone)) {
extract($sqlonerow);
if ($selectThis == 0){
print "<option value=\"$step_id\" SELECTED>#$step_id $description</option>\n";
$selectThis = 1;

}
else{
print "<option value=\"$step_id\">#$step_id $description</option>\n";
}
}
print "</select>\n</td>\n";
?>
<TD ><B>combo2:</B></TD>
<td><select name="chance" size="1" class="text" tabindex="11" >\n";
<?php


$sqltwo = mysql_query("SELECT * FROM table2");
while ($sqltworow = mysql_fetch_array($sqltwo)) {
extract($sqltworow);

print "<option value=\"$chance_id\">$percentchance% $definition</option>\n";

}
print "</select>\n</td>\n";


?>


if i select combo1, item #1,item #2, item #3, item #4 the value in combo2, should display item #1, in combo2.
if i select combo1, item #5, the value in combo2, should be changed to the item #2 of combo2 automatically.
How can i do it.
please help.
Thanks

rosy
11-13-2006, 05:11 PM
I tried using the same above concept and found the result and it works.
Thanks.:-)

rosy
11-13-2006, 05:17 PM
Hi,
Using the above i can able to show or hide the combo box but in different positions, i would like to show or hide in same position. How can i make it?
Is that do i need to do something in style:position-relative ?
Thanks.