Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
58
rated 0 times [  62] [ 4]  / answers: 1 / hits: 72502  / 12 Years ago, sun, july 8, 2012, 12:00:00

I have different JavaScript function associated with each option tag to toggle layers on/off in an OpenLayers map. It works fine Opera, Firefox and IE9, but not in Chrome and Safari. I read that I could use onchange on the select tag, but since I'm new to JavaScript, I don't really how it would call four different functions?



<select size=1 name=usgsfeed id=usgsfeed>
<option value=usgs_hour onclick=display_usgs_hour();>Past hour, all earthquakes</option>
<option value=usgs_day onclick=display_usgs_day(); SELECTED>Past day, magnitude > 1</option>
<option value=usgs_week onclick=display_usgs_week();>Past week, magnitude > 2.5</option>
<option value=usgs_month onclick=display_usgs_month();>Past month, magnitude > 2.5</option>
<option value=none onclick=display_none();>None</option>
</select>

More From » html

 Answers
1

Call the function according to the select's value:



<select onchange=window['display_'+this.value]();>


If the value is usgs_hour the concatenation would be 'display_' + 'usgs_hour' === 'display_usgs_hour' and that function is called.



jsfiddle demo: http://jsfiddle.net/Ag3kh/


[#84396] Friday, July 6, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
madalynn

Total Points: 342
Total Questions: 95
Total Answers: 106

Location: Turkmenistan
Member since Sat, Apr 16, 2022
2 Years ago
;