select form variable to javascript function.

P

pukeko.taniwha

Hi, i am trying to get a function to work, but i am still learning
javascript and i really need some help.
i have a select form
<select ="menu1" onChange="onMapClick(menu1.value)">
<option selected>Select Dataset</option>
<option value="massey_07">Turitea 2007</
option>
<option value="Massey_02_2003">Turitea
2003</option>
<option value="All_orthos">Turitea</
option>
<option value="albany2005">Albany 2005</option>
<option value="albany2004">Albany 2004</option>
<option value="albanycom">Albany</option>
</select>

and i want to make the value from this form into a variable and pass
it to this function as "imageSRC"

<script language="javascript">
// User clicked a new region. Parameter is name of that region.
function onMapClick(){
menu1.value = imageSRC;
document.ECWView1.DeleteAllLayers();
document.ECWView1.AddLayer("ECW", "ecwp://" + document.location.host +
"/Massey/images/Massey/" + imageSRC + ".ecw", "RasterLayer",
"freecache=TRUE");
}
</script>

i have tried lots of different things, but i firefox's firebug console
tells me that -

menu1 is not defined
onchange(change )

what am i doing wrong?
sorry, this is probably really basic.
Matt
 
V

VK

Hi, i am trying to get a function to work, but i am still learning
javascript and i really need some help.
i have a select form
<select ="menu1" onChange="onMapClick(menu1.value)">

Selected value access in <select> is weird and counterintuitive in
JavaScript - an original legacy oops from Netscape 2 that is too late
to change now for legacy issues.

First you need to get the index of currently selected option over
selectElement.selectedIndex property and then use it for
selectElement.options collections. In total:

<select ="menu1" onChange="
onMapClick(this.options[this.selectedIndex].value);
">
 
P

pukeko.taniwha

Hi - solved my own problem - always the way isnt it...
i changed
<select = "menu1"
to
<select name = "menu1"

and on the function
function onMapClick(){
to
function onMapClick(imageSRC){
and its working a treat.

Matt
 

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,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top