twilitegxa Posted August 25, 2009 Share Posted August 25, 2009 I have the following simple form with a button that is supposed to add what the user puts in the text box into the select list as an option. But, my function doesn't appear to be doing anything. When I put text into the input text box, nothing happens. Here is my code: <html> <head> <title>Untitled Document</title> <script type="text/javascript"> function addMagazine() { if (document.forms[0].elements[31].value == "") window.alert("You must enter a magazine name."); else { var magazine = new Option(); magazine.text = document.forms[0].elements[31].value; magazine.value = document.forms[0].elements[31].value; nextItem = document.forms[0].magazines.length; document.forms[0].magazines.options[nextItem] = magazine; document.forms[0].elements[31].value = ""; } } </script> </head> <body> <form action="FormProcessor.html" method="get"> <p>Magazine <input type="text" size="68" /></p> <p><input type="button" value="Add Magazine" onclick="addMagazine();" style="width: 120px" /></p> <p><select name="magazines" multiple="multiple" size="10" style="width: 500px"> <option value="none">Enter the magazine you subscribe to</option> </select></p> </form> </body> </html> Can anyone see something I am doing wrong? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.