I think some explanation about a few basic principles is in order here.
var myClientSide = '<%=myServerSide%>';
In this code, the <%= %> is a short cut for Response.Write(myServerSide) at the server
. So what happens is that a server side
variable is written to the client side.
Omitting the = would result in just a variable name listed in the code, but no output.
In your select function, the value of SomeASPVariable I proposed shouldn't be the name of the form element, but the actual value you want to preselect. So, if you have a drop-down with first names, SomeASPVariable could contain John for example, again at the server, to preselect the item wih the value John.
Then this code:
would end up like this:
I modified the code a bit so it works now, and should run in all browsers:
// at this point, itemToSelect holds 'John'
// Get a reference to the drop-down list
var myDropdownList = document.frmTest.lstNames;
// Loop through all the items
for (i = 0; i < myDropdownList.options.length; i++)
if (myDropdownList.options[i].value == itemToSelect)
myDropdownList.options[i].selected = true;
<form id="frmTest" name="frmTest">
<select id="lstNames" name="lstNames">
The only change to this code you must make is the value you pass to the function. Instead of:
you should do something like this:
Does this clarify things??
Everyone is unique, except for me.
While typing this post, I was listening to: Kill You
(Track 14 from the album: Life Is Peachy
) What's This?