473,491 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

javascript associative array

is there a way to get the index of an array aside from the values that
you passed from a form?

<form name="details">
<label for="fname">
first name:
<input type="text" name="name['firstname']" id="fname" />
</label>
<label for="mname">
middle name:
<input type="text" name="name['middlename']" id="mname" />
</label>
<label for="lname">
last name:
<input type="text" name="name['lastname']" id="lname" />
</label>
<label for="hnum">
home number:
<input type="text" name="num['homenumber']" id="hnum" />
</label>
<label for="mnum">
mobile number:
<input type="text" name="num['mobilenunber']" id="mnum" />
</label>
<label for="fnum">
fax number:
<input type="text" name="num['faxnumber']" id="fnum" />
</label>
<input type="button" name="showName"
onclick="display('details','name[]')" />
<input type="button" name="showNum" onclick="display('details',
'num[]')" />
</form>

so here is my script.(which doesnt really work right)

function display(the_form,the_element){

var elts = document.forms[the_form].elements[the_element];
var elts_cnt = (typeof(elts.length) != 'undefined')? elts.length : 0;
var param = '';

if (elts_cnt)
{

for (var i in elts)
{
param = param + i + "=" + elst[i] + "&";
} // end for

param = param.substring(0,(param.length-1));

} // end if

alert(param);

}
i need to make the param like this

firstname=joe&middlename=smith&lastname=wilson&... ...

Sep 26 '05 #1
1 1444
ma******@gmail.com said the following on 9/26/2005 1:29 AM:
is there a way to get the index of an array aside from the values that
you passed from a form?


What array? There are no JS Arrays defined in the code you posted. Are
you using PHP server-side by chance? PHP likes those arrayName[] constructs.

And, it would be better suited as an object instead of an array.

If the page is generated, have it generate objects for each section you
want to keep up with. Then its a matter of going through the object's
properties and getting what you want. But, there is a simpler way if you
simply redefine your name/IDs/Labels so that it becomes easier.

The whole thing begs the question "What are you trying to accomplish
exactly?"

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Sep 26 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
2485
by: Kevin | last post by:
Help! Why are none of these valid? var arrayName = new Array(); arrayName = new Array('alpha_val', 1); arrayName = ; I'm creating/writing the array on the server side from Perl, but I
27
11116
by: Abdullah Kauchali | last post by:
Hi folks, Can one rely on the order of keys inserted into an associative Javascript array? For example: var o = new Object(); o = "Adam"; o = "Eve";
6
2712
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is...
4
1656
by: meltedown | last post by:
Theres something very basic about javascript arrays I'm missing. The value of unit.value is 17.00 and value of the qty.value is 5 and I put these values into an array: myarray.value]=qty.value;...
35
6586
by: VK | last post by:
Whatever you wanted to know about it but always were affraid to ask. <http://www.geocities.com/schools_ring/ArrayAndHash.html>
8
1665
by: Doug Lerner | last post by:
I have this snippet of client side code running: var makeField = document.forms; alert("makeFieldName name,length,type=" + makeFieldName + ", " + makeField.name + "," + makeField.length + ","...
104
16845
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
41
4873
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
0
7190
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7360
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5451
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4881
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4578
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3086
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
280
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.