Ok, due to PHP and JS naming restrictions I'm finding it exceedingly difficult, or perhaps I'm dense, to post multiple selected options from a select list.
If I name my form: name[] ( effectively declaring an array ) then PHP picks up all the selected options no problem, however, I need to process to do a number of things with JS before i post the form and JS doesn't like element names like: name[].
I tried something like this to no avail also:
<form name="f1" ...>
<select name="f1[choices[]]"...>
When i name like so PHP does get all the posted selections, however, i am unable to do my client side processing in JS with this sort of naming.
Can anyone help me out here?
Thanks,
Pete
Getting PHP to play nice with Javascript
Moderator: General Moderators
- gite_ashish
- Forum Contributor
- Posts: 118
- Joined: Sat Aug 31, 2002 11:38 am
- Location: India
hi,
see the code below:
See php man:
http://www.php.net/manual/en/faq.html.php
Thanks, i also tried it today only !
see the code below:
Code: Select all
<SCRIPT type="text/javascript">
function setTo()
{
j = document.frm.elementsї'monthї]'].length;
for( i = 0; i < j; i++ )
{
if ( document.frm.elementsї'monthї]'].optionsїi].selected )
{
alert( 'Selected: ' + document.frm.elementsї'monthї]'].optionsїd
ocument.frm.elementsї'monthї]'].selectedIndex].value );
}
else
{
alert( 'Unselected: ' + document.frm.elementsї'monthї]'].options
їi].value );
}
}
return false;
}
</SCRIPT>
<PRE>
<H3>PHP-JavaScript</H3>
<FORM name=frm method=POST onSubmit="return setTo();">
Name: <INPUT type=text name=txtName>
Month: <SELECT name="monthї]" multiple size=6>
<OPTION VALUE="1">January</OPTION>
<OPTION VALUE="2">February</OPTION>
<OPTION VALUE="3">March</OPTION>
<OPTION VALUE="4">April</OPTION>
<OPTION VALUE="5">May</OPTION>
<OPTION VALUE="6">June</OPTION>
<OPTION VALUE="7">July</OPTION>
<OPTION VALUE="8">August</OPTION>
<OPTION VALUE="9">September</OPTION>
<OPTION VALUE="10">October</OPTION>
<OPTION VALUE="11">November</OPTION>
<OPTION VALUE="12">December</OPTION>
</SELECT>
<INPUT type=submit value=Submit>
</FORM>
</PRE>See php man:
Thanks, i also tried it today only !
I'm using JS in this case because I'm restricting the browser to IE, ( it's for an intranet where I work ).
The JS is perfect here because I'm building numerous select lists from other lists etc...so using JS I avoid a ton of page requests.
If this were for the "real world" I'd obviously go another route.
Regards,
Pete
Also, thanks to gite_ashish, I'll give that script a try.
The JS is perfect here because I'm building numerous select lists from other lists etc...so using JS I avoid a ton of page requests.
If this were for the "real world" I'd obviously go another route.
Regards,
Pete
Also, thanks to gite_ashish, I'll give that script a try.