Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > javascript associative array

Reply
Thread Tools

javascript associative array

 
 
markrenn@gmail.com
Guest
Posts: n/a
 
      09-26-2005
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&... ...

 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      09-26-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript Associative array syntax not valid. Why?!?!?!? Kevin Javascript 8 12-21-2007 05:03 PM
Why "associative" in associative container? desktop C++ 5 06-26-2007 07:49 AM
Array and Hash (Associative array) in JavaScript v.3.0 VK Javascript 36 08-03-2005 02:39 PM
<FAQENTRY> Array and hash (associative array) VK Javascript 47 07-13-2005 06:27 AM
[newbie]saving and reading array of associative array Yvon Thoraval Ruby 5 09-17-2003 07:54 PM



Advertisments