strange behavior when changing select's value

T

TDN

Hi,

I expect to see "foo" for the 2nd alert. Instead, the value of select is
cleared. Am I missing something? Thanks for your help.

<html>
<head><title>Foo</title>
<script language="javascript">
<!--
function foo()
{
alert('Before change: ' + document.control.titleFont.value);
document.control.titleFont.value = 'foo';
alert('After change: ' + document.control.titleFont.value);
}
-->
</script>
</head>
<body>
<form name="control" method="POST">
<select name="titleFont">
<option value="sans-serif">Arial</option>
<option value="serif">Times</option>
</select>&nbsp;
<input type="submit" name="control" value="Submit" onclick="return
foo()"/>
</form>
</body>
</html>
 
T

TDN

[snipped]

Well, I found out that I need to change the value of the selected index.
Interesting indeed! Here goes:

.....
var index = document.control.titleFont.selectedIndex;
document.control.titleFont[index].value = 'foo';
alert(document.control.titleFont.value);
.....

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top