[SOLVED] Moving an array of selected values to the next page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
okposi
Forum Newbie
Posts: 4
Joined: Sun Apr 17, 2005 12:47 am
Location: Canada

[SOLVED] Moving an array of selected values to the next page

Post by okposi »

Hi Guys,
Could someone please help. I have jused a javascript to collect an array of items selected by a user.How can I send this array to another page for processing. More specifically, How can I pass this array to a php code to iterate though the items in the array.
Thanks for your help.
OJ
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

can you post your code?
okposi
Forum Newbie
Posts: 4
Joined: Sun Apr 17, 2005 12:47 am
Location: Canada

Post by okposi »

Code: Select all

<script language = &quote;Javascript&quote;>
	function getAllCheckedBoxes(){
	var checkbox_choices = 0;
	var selectedArray= new Array();

		// Loop from zero to the one minus the number of checkbox button selections
		for (counter = 0; counter < checkbox_form.checkbox.length; counter++)
		{

			// If a checkbox has been selected it will return true
			// (If not it will return false)
			if (checkbox_form.checkboxїcounter].checked)
			{ 	
				selectedArray.push(checkbox_form.checkboxїcounter].value);
				checkbox_choices = checkbox_choices + 1; }

			}
		return selectedArray;

		}
	}
</script>
Here is the form

Code: Select all

<form method=&quote;get&quote; action=&quote;Show.php&quote; 
onsubmit=&quote;return checkbox_checker()&quote; name=&quote;checkbox_form&quote;>
<input type=&quote;checkbox&quote; value=&quote;1&quote; name=&quote;checkbox&quote;>Hank Aaron<br>
<input type=&quote;checkbox&quote; value=&quote;2&quote; name=&quote;checkbox&quote;>Ted Williams<br>
<input type=&quote;checkbox&quote; value=&quote;3&quote; name=&quote;checkbox&quote;>Hank Greenberg<br>
</form>

Then I want to pass the array returned from the javascript to a php function that will do the following:

Code: Select all

for($i=0;$i<selectedArray.length;$i++){
 print(selectedArrayї$i]);
 
 
 }


I will appreciate if someone can help me.Is it possible to pass the array returned by javascript to php session?. If so how can I do that
Thanks


feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your code is mixing Javascript and PHP without any translation between.

If you simply allowed the form to submit naturally, show.php would get each of the selected checkboxes.
okposi
Forum Newbie
Posts: 4
Joined: Sun Apr 17, 2005 12:47 am
Location: Canada

Post by okposi »

Thanks for your response. If you look at the code, all the check boxes have the same name but different values. I tried that approach and I am only able to fetch the last value.
The post will look like:
checkbox=1&checkbox=2&checkbox=3
Therefore, I will only get Checkbox=3 on the next page.
I still need more help.
Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

change the name to 'checkbox[]' so php will create an array of the values...
okposi
Forum Newbie
Posts: 4
Joined: Sun Apr 17, 2005 12:47 am
Location: Canada

Post by okposi »

Thanks!! feyd,
It solved my problem. I did some twicking to manage th earray on the next page.
That was a smart solution for me.I don't even need use javascript any more.

Cheers
OJ
Post Reply