Forum Moderators: open

Message Too Old, No Replies

Changing combobox value with JS

script is inside body tag

         

longboy

11:08 pm on Jan 21, 2008 (gmt 0)

10+ Year Member



hi
i am trying to change selectedIndex of a combobox but have no idea how to do that. here is code

<script language='javascript'>
seldisp = documnet.getElementById('displayed');
seldisp.selectedIndex = '1';
</script>

<form name="editpage">
<select name="displayed">
<option>Yes</option>
<option>No</option>
</select>

</form>

error:
document is undefined.

this script is inside body tag and i have to use it inside body since this is being used in PHP.

Thanks

eelixduppy

11:42 pm on Jan 21, 2008 (gmt 0)



Hello.

First off you have a misspelling. Document was spelled incorrectly. The following should work:


<script type="text/javascript">
seldisp = document.editpage.displayed;
seldisp.selectedIndex = 1;
</script>

Notice how I removed the "getElementById" method because you actually didn't specify the ID of the element, only the name. If you wanted to use what you had, it should be written like the following:


<select [b]id[/b]="displayed">

Fotiman

3:11 pm on Jan 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Also note that the language attribute on the script tag is invalid. Instead, use type="text/javascript" as in the example above.