Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old January 19th, 2004, 06:47 PM
mugane mugane is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Charlottesville, VA USA
Posts: 425 mugane User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to mugane Send a message via Yahoo to mugane
How to make an array in a html form

Well, I'm at a loss...

Here's the problem, any suggestions more than welcome... (thanks!)

I have an array of strings (PHP) that I want to display on my page. I also need to have the user be able to select any number of these strings by clicking the text, and I need to have access to a list of the selected items in both javascript and php. Hence, I want to have a hidden form field for each item, and I want this to be an array - so that I can iterate through it in javascript and later in php.

I have not been able to get this working. Can it be done? Ideally, an associative array, say "elementlist" with each index being one of the strings and the value being either "selected" or ""?

this is what I have
php Code:
Original - php Code
  1. <?
  2. // $elements is my array of strings
  3. while (list($key,$value)=each ($elements))
  4. {
  5.  echo "<input type=hidden name=elementlist['$value']><SPAN onclick="selectitem();">$value</SPAN><BR>";
  6. }
  7. ?>

the javascript:
Quote:
function selectitem()
{
elementlist['$value'].value='selected';
}
I just need to get to the point where I can access the elementlist[] array in javascript and have it passed as an array to php when the form is submitted. I was able to get the form to submit an array $_POST[elementlist] at one point but it won't do it anymore

Thanks for any input...

Peter

Reply With Quote
  #2  
Old January 19th, 2004, 08:13 PM
zombie zombie is offline
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: serbia
Posts: 1,876 zombie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: How to make an array in a html form

1) why don't you simply use checkboxes?

2) html output whould be

php Code:
Original - php Code
  1. echo "<input type='..' name='elementlist[$value]' />..."


3) in javascript to access elements with "strange[names]" you do this document.formname.elements['strange[name]']

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > How to make an array in a html form


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT