Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting JS to play nice with PHP

Status
Not open for further replies.

phpPete

Programmer
Feb 25, 2002
88
US
Ok dokie!

I make selections from one large select list, then add them to one smaller select list. No problem.

Problem is that only the last item selected is posted.

Now I know if I name the select as : name[] it declares an array and all the selcted options are posted, however, JS doesn't like that syntax, at least I don't think it does, since I'm getting null error notices when i use it.

naming example is:
<form name=&quot;f1&quot; method=&quot;post&quot; action=&quot;<?php echo $_SERVER['PHP_SELF'] ?>&quot;>
<select name=&quot;chosen&quot; multiple=&quot;multiple&quot; size=&quot;10&quot; id=&quot;TEST&quot;>


Thanks in advance,

Pete
 
Square brackets are reserved characters, and not allowed in element names accessed through Javascript. As well, id or element names that begin with numbers are not allowed, either, and will create errors on the page if accessed with Javascript.
 
OK...got that. Now as to posting all the selected options...any ideas?

Thanks

Pete
 
hi pete,

yes: loop through all options in your select and check for the property &quot;selected&quot;. assuming you've created a hypothetical function moveToList() to handle moving from &quot;chosen&quot; to the smaller list, something like this should work:
[tt]
var sel = document.forms[0].chosen;

for (ndx = 0; ndx < sel.length; ndx++) {
if (sel.options[ndx].selected)
moveToList(sel.options[ndx]);
}
[/tt]
=========================================================
if (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top