Jump to content

[SOLVED] add to select list function not working. Can anyone help!!?


twilitegxa

Recommended Posts

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.