Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

select box comma seperated list into a javascript function 1

Status
Not open for further replies.

gruvn

Programmer
Oct 15, 2004
24
CA
Hey all you javascript masters,

Can someone clue in what I'm doing wrong? I am trying to take a comma separated list of data (4 values) and pass them to an existing function zoomToPlace().

The function itself works - I can do:
<a href="JavaScript:zoomToPlace(1,6,8,10)" target="mapFrame">Zoom to this feature</a>

with no problem. My problem arises when I try to pass other groups of comma seperated values to this function via a select box like the following...

<form name="form1" >
<select name="jumpmenu" onChange="JavaScript:zoomToPlace();">
<option>Jump to...</option>
<option value="2,5,7,9>Place 1</option>
<option value="4,7,3,11">Place 2</option>
</select>
</form>

I don't think I can show the function (it's copyrighted -- not by me), but i assure you that it is expecting 4 comma separated values.

I've looked and looked at faqs about this, but can't find anything on using multiple values.... Any thoughts?

Thanks!

gruvn
 
In your example you're not passing any values to the zoomToPlace() function. To pass it the value of the selected option, use <select name="jumpmenu" onchange="zoomToPlace(this.options[this.options.selectedIndex].value);">

Also, in your example you're not closing the quotes around the first option value which will really mess things up.

HTH.
 
Close, theboyhope-

Code:
<select name="jumpmenu" onchange="zoomToPlace(this.options[this.selectedIndex].value);">

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Why put in the extra characters?

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Well, to give a more serious answer: There are shorter versions than both of ours that will work on most platforms. I think most people just go with the one that they have found to be the most robust.
 
Out of curiosity, what shorter versions work x-browser?

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Just this.value by itself will work, certainly in the newer browsers.

But I just go with the one that has never let me down. I expect you're doing likewise.
 
I certainly am. this.value will return the value of the selected option in new browsers, but has nothing to do with selectedIndex.

either way, the solutions above are more than sufficient for the poster.

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top