[thelist] Javascript - detecting which SELECT!

Senthil Kumar.R senthil at eclinic.com.au
Tue Dec 5 04:30:05 CST 2000


hi

You might find it quit difficult to pass number of values in this form.. and
might end up with a big mess of names.

The easy way to do this is using arrays, you can pass the values using
arrays in your form, and then retrieving them in your JavaScript.

for example,

	document.forms[0].elements[i].name
		or
	document.forms[0].elements[i].value
	where i is the number of the array element, use
document.form[0].elements.length- to find the number of elements.


which will give u the value of the particular element in the array. One
advantage in this is, u can pass  multiple arrays  with multiple values.
hope this should solve u'r problem.
good day

regards
senthil kumar.R
SummitWorks Tech. Pty. Ltd.
Chennai.
(http://www.summitworks.com)

-----Original Message-----
From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org]On Behalf Of Steve Cook
Sent: Tuesday, December 05, 2000 9:18 PM
To: 'thelist at lists.evolt.org'
Subject: [thelist] Javascript - detecting which SELECT!


Hi folks,

I'm writing an aplication that uses a number of select elements on a page.
Selecting a value in one should fire up a JavaScript function that redirects
to a new page, with the selected value included within a query string.

After reading 3 JavaScript tutorials, I'm most of the way there, but I'm
stuck on trying to detect which select I have clicked on!

I know that the actual element is found like this:

	window.document.form_name.select_name.selectedIndex
returns the array number, you can then type
	window.document.form_name.select_name.options[that_number].text
to find out what was actually selected

All well and good, but if I have multiple select elements on the page, how
do I detect "select_name" in the code above. I've tried:

	window.document.form_name.elements.selectedElement

to detect the element (and various permutations of that). I've also tried
passing the info in my onChange like this:


onChange="leapTo(window.document.theForm.how.options[selectedIndex])"

Where "theForm" and "how" are set to the names I'm actually using in the
script.

The horrible thing is I'm sure this is terribly easy. Someone please
enlighten me :-)

.steve

(You'd never believe I once wrote an evolt article about a JavaScript
application I wrote! (http://evolt.org/index.cfm?menu=8&cid=567) I actually
really dislike JavaScript. I find it counterintuitive, the DOM quite frankly
scares me and I always end up feeling I have to sweat blood to make it do
the simplest thing :-/


----------------------------------
   WapWarp - http://wapwarp.com
 Wap-Dev - http://www.wap-dev.net
 Cookstour - http://cookstour.org
----------------------------------

---------------------------------------
For unsubscribe and other options, including
the Tip Harvester and archive of TheList go to:
http://lists.evolt.org Workers of the Web, evolt !





More information about the thelist mailing list