I'm new to javascript and need a little help. I have a dropdown menu with some script to display a input field if 'other' is selected. Everythig works except I want it to appear on the same line as the menu. How do I do it? Here's the code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript"> function showNewCountry() { theHiddenFields=document.getElementById('hiddenFields'); theHiddenFields.style.display=(document.form1.country.value==0)?'':'none'; } </script> </head> <body> <form id="form1" name="form1" method="post" action=""> <select name="country" id="country" onChange="showNewCountry()"> <option value="1">U.S</option> <option value="2">Mexico</option> <option value="3">Canada</option> <option value="0">other</option> </select> <div id="hiddenFields" style="display:none"><label>Enter Your Country:</label><input type="text" name="newCountry" id="newCountry" /></div> </form> </body> </html>
It helps if you use the code tags when posting code. It's the # on the toolbar. Highlite the code then click #. You shouldn't put a div or anything other than form fields, inside a form. Please and thank you, don't hurt, either. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Any Title</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script type="text/javascript"> </script> <style type="text/css"> body {background-color:#eae3c6;margin-top:60px} form {width:620px;margin:auto;font-family:times;font-size:12pt} fieldset {width:610px;background-color:#f0fff0;border:1px solid #87ceeb} legend {font-family:times;font-size:14pt;color:#00008b;background-color:#87ceeb;padding-left:3px;padding-right:3px;margin-bottom:5px} label {font-family:times;margin:5px} .submitBtn {font-family:tahoma;font-size:10pt;display:block;margin-left:auto;margin-right:auto;margin-top:5px;margin-bottom:5px} </style> </head> <body> <form action="" method="post"> <fieldset> <legend>Form</legend> <select name="country" onchange="(this.value=='0') ? document.getElementById('newCountryLbl').style.display='' : document.getElementById('newCountryLbl').style.display='none'"> <option value="1">U.S</option> <option value="2">Mexico</option> <option value="3">Canada</option> <option value="0">other</option> </select> <label style="display:none" id="newCountryLbl">Enter Your Country: <input type="text" name="newCountry" ></label> <input type='submit' name='submit' value="Submit" class='submitBtn'> </fieldset> </form> </body> </html> Code (markup):