Welcome to WebmasterWorld Guest from 54.162.227.136

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Multiple GETs w. the same name

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

10+ Year Member



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.

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

10+ Year Member



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? :(

 

Featured Threads

Hot Threads This Week

Hot Threads This Month