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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.