469,271 Members | 1,381 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

This Form Elements ID

Is there a way to determine the current form element without having to
loop through the array or determining by name? Since the form I am
using integrates with PHP which parses the values as a
multi-dimensional array, the names of the fields are not unique. I
need to set the value of the previous form field from a select box.
It seems that the easiest way would be to determine the elements id
and set the current_id-1.value to this value.

Any ideas?

Example:
<input type="text" name="name[]" value="">
<select name="select"
onchange="document.form.elements[(thisid-1)].value=this.value">
<option value="1">1</option>
<option value="2">2</option>
</select>
Aug 6 '06 #1
2 1855
Tyrone Slothrop said the following on 8/6/2006 2:53 PM:
Is there a way to determine the current form element without having to
loop through the array or determining by name? Since the form I am
using integrates with PHP which parses the values as a
multi-dimensional array, the names of the fields are not unique. I
need to set the value of the previous form field from a select box.
It seems that the easiest way would be to determine the elements id
and set the current_id-1.value to this value.

Any ideas?

Example:
<input type="text" name="name[]" value="">
<select name="select"
onchange="document.form.elements[(thisid-1)].value=this.value">
<option value="1">1</option>
<option value="2">2</option>
</select>
If PHP is producing that code, then PHP can give you the name of the
previous input:

this.form.elements['<? previousName >'].value=this.value;

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 6 '06 #2
On Sun, 06 Aug 2006 15:42:59 -0400, Randy Webb
<Hi************@aol.comwrote:
>Tyrone Slothrop said the following on 8/6/2006 2:53 PM:
>Is there a way to determine the current form element without having to
loop through the array or determining by name? Since the form I am
using integrates with PHP which parses the values as a
multi-dimensional array, the names of the fields are not unique. I
need to set the value of the previous form field from a select box.
It seems that the easiest way would be to determine the elements id
and set the current_id-1.value to this value.

Any ideas?

Example:
<input type="text" name="name[]" value="">
<select name="select"
onchange="document.form.elements[(thisid-1)].value=this.value">
<option value="1">1</option>
<option value="2">2</option>
</select>

If PHP is producing that code, then PHP can give you the name of the
previous input:

this.form.elements['<? previousName >'].value=this.value;
True if the previous field name was not part of an array of names. JS
gets a little strange when you name fields using "name[<?=$i?>]."

I managed to figure out that I could actually name the select with a
unique name since it is just pasting a value, which made the whole
thing a lot easier.

Being too damned slick for your own good can be a challenge at times.
;-)
Aug 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by Michal Mieszkowski | last post: by
12 posts views Thread by Pudlik, Szymon | last post: by
5 posts views Thread by Phil Powell | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.