Jump to content

Retrieving information from a form using post


Bendude14

Recommended Posts

I have this code

 

  <select name="copylist2" multiple size=10
   onDblClick="Selectbox.copySelectedOptions(this.form.copylist2,this.form.copylist1,this.form.copysort.checked)">

 

and the submit button is called update and i am trying to retrieve it like so

 

<?php

if(isset($_POST['update'])) {

 

$players = $_POST['copylist2'];

 

echo $players;

 

?>

 

It does process the code but i just get undefined index copylist2 error.

 

Thanks

Link to comment
Share on other sites

You can't really directly refer to your select box like this.

 

Try this:

  <select name="copylist2" multiple size=10
   onDblClick="Selectbox.copySelectedOptions(this,document.forms[0].copylist1,document.forms[0].copysort.checked)">

 

I assumed that you only have 1 form in your document. Using document.forms[0] referred to your current form.

 

The 'this' was referred from the double-click event from the select box itself. So 'this' can represent the select box object.

Link to comment
Share on other sites

I have two list boxes and the javascript allows the names on the left to be moved by the user to the right and then when you click update i want to be able to process the information that was selected.

 

I think it would be pointless for me to post the js because its a file i used from the javascript tool box and it is all in shorthand?

 

if someone knows of any simpler scripts to get the same effect i would be happy to use them.

 

thanks

Ben

Link to comment
Share on other sites

A select object will only send one value to the POST so you will have to use javascript to send a bunch of values. Here is something to get you started:

<script language="JScript">
function addItem(e)
{
var newOp = document.createElement('OPTION');
frmTest.selNew.add(newOp);
newOp.innerText=e.innerText;
newOp.name=e.name;
newOp.value=e.value;

var newHid = document.createElement('INPUT');
newHid.type="HIDDEN";
newHid.name=e.name;
newHid.value=e.value;
frmTest.appendChild(newHid);
}
</script>
<form id="frmTest" method=POST action="test.php">
<select id="selOrig" name="selOrig" size=6 multiple onchange="addItem(document.getElementById(this.value))">
<option id="1" value="1" name="Item1">Item1
<option id="2" value="2" name="Item2">Item2
<option id="3" value="3" name="Item3">Item3
<option id="4" value="4" name="Item4">Item4
<option id="5" value="5" name="Item5">Item5
<option id="6" value="6" name="Item6">Item6
</select>
<select id="selNew" name="selNew" size=6 multiple>
</select>
<input type=submit>
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.