473,325 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

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 1903
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: Michal Mieszkowski | last post by:
i have a block of html code looking like this <FORM name=myform> <INPUT type=text name=firstname> <DIV id=mydiv> <INPUT type=text name=address> </DIV> </FORM> i can access firstname field...
5
by: Nick Calladine | last post by:
Learning : Loop to list all dropdown box values on a form Can some one point me in the right direction : I have a form which I want to loop through I basically want to get all the selected...
12
by: Pudlik, Szymon | last post by:
Hi, I've written some code: function onSubmit(form){ for (var i = 0; i < form.elements.lenght; i++){ if (form.elements.disabled == 1) form.elements.disabled = 0; }
5
by: Phil Powell | last post by:
Requirement is to refresh a page in the form of a continual form submittal (for server-side validation and action) Here is the Javascript I came up with that I thought would do that: <script...
4
by: SteveKlett | last post by:
I have a subset of form items that I need to perform different operations on (enable/disable, clear values, change style, etc) rather than hard code the IDs or names I would like to recursively...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.