homepage Welcome to WebmasterWorld Guest from 54.196.197.153
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Multiple GETs w. the same name
kreeves




msg:1266393
 4:32 pm on May 11, 2005 (gmt 0)

The code I'm writing is using javascript and PHP.

Basically, it's a form that people add things to a drop down list w. javascript. The form is then submitted and all of the things in the drop down list (if selected) are submitted through GET (Which I will probably change later.)

I've done this before in PHP only where I could just assign an incrementer at the end of the "name" variable on each text field. However, I have multiple results going to the same "name" field now.

Here's an example of what shows when I do a print_r on $_REQUEST

mySelect = test

But my url looks like this
domain.com/document.phtml?mySelect=yep&mySelect=hey&mySelect=test

It grabs the last value, I understand that. Anyway to stop this behavior? Or am I just hoping for the impossible.

 

kreeves




msg:1266394
 5:51 pm on May 11, 2005 (gmt 0)

Nevermind, I figured it out. For anyone else trying to do something similar, this is what I did ...

script.js
function addSelect(name,value)
{
var x=document.getElementById('mySelect[]')
x.options[x.options.length] = new Option(name, value);
x.size = x.length
}
function sizeChange()
{
var x=document.getElementById('mySelect[]')
var length=x.length
x.size=length
x.multiple=true
}

page.phtml
<?
print "<html>";
print "<head>";print "<script src=\"script.js\"></script>";
print "</head>";
print "<body onload=\"sizeChange()\">";
print "<form name=\"form\" action=\"{$_SERVER{'PHP_SELF'}}\">";
print "Name : <input type=\"text\" name=\"name\"><br>";
print "Value : <input type=\"text\" name=\"value\"><br>";
print "<br>The select box:<br>";
print "<select id=\"mySelect[]\" name=\"mySelect[]\">";
print "<option>-- Add Things --</option>";
print "</select>";
print "<br><br>";
print "<input type=\"button\" onclick=\"addSelect(document.form.name.value,document.form.v
alue.value)\" value=\"Add values\"><BR>";
print "<input type=\"submit\" value=\"Test PHP Submit\" name=\"submit\" onclick=\"printVal
ues\">";
print "</form>";
print "</body>";
print "</html>";
print "<pre>";
print_r($_REQUEST);
print "</pre>";
?>

PS. What's up with these forums. Can't have new lines in code tags? :(

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved