html - Basic javascript isn't working - display block -
if user selects "house" want new select option box pop up. nothing happening.
function showfamilies(){ if(pt.selectedindex == 1) document.getelementbyid('families').style.display = 'block'; if(pt.selectedindex != 1) document.getelementbyid('families').style.display = 'none'; } <select id="pt" value="pt" name="pt" onchange="showfamilies()"> <option value="" name="">select</option> <option value="1" name="1">house</option> <option value="2" name="2">commercial</option> </select> <div id="families" style="display:none">families: <select name="amin_families"> <option value="1" name="condo">1</option> <option value="2" name="co-op">2</option></select> </div>
redefined if
statement. works fine now.
<!doctype html> <html> <head> <script type="text/javascript"> function showfamilies(pt){ if(pt.selectedindex == 1) { document.getelementbyid('families').style.display = 'block'; } else { document.getelementbyid('families').style.display = 'none'; } } </script> <title></title> </head> <body> <select id="pt" value="pt" name="pt" onchange="showfamilies(this)"> <option value="" name="">select</option> <option value="1" name="1">house</option> <option value="2" name="2">commercial</option> </select> <div id="families" style="display:none">families: <select name="amin_families"> <option value="1" name="condo">1</option> <option value="2" name="co-op">2</option></select> </div> </body> </html>
Comments
Post a Comment