Store value from query string into an array

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

adeelzia
Forum Newbie
Posts: 22
Joined: Thu Jul 06, 2006 5:31 pm

Post by adeelzia »

Volka Wrote: So why can't the select element have the name select2[] ?
This is the first page where different values from the listbox named "select1" have to be added into listbox named "select2",make another page for yourself and press the generate report button but before that make the name of the second listbox to "select2[]" and you will see its not working.........how else should I elaborate all you guys :? ...............no one is getting my point........ :x[/quote]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

adeelzia wrote:make another page for yourself and press the generate report button but before that make the name of the second listbox to "select2[]" and you will see its not working
not true.
a) You can use select2[] in javascript - as long as you do it right
b) You don't need the name attribute of the select element in your javascript function, use id and the appropriate document methods instead,
i.e. <select id="select2" name="select2[]" multiple="muliple"> and document.getElementById("select2");
adeelzia
Forum Newbie
Posts: 22
Joined: Thu Jul 06, 2006 5:31 pm

Post by adeelzia »

Dear Volka,Where am I using document.getElementById("select2"); :( .............ur concept does looks strong.......can u help me further in this,plz make me a code of this page in such a way that the select2 values should go as different named in the query string..........I am really stuck up in this,waiting for ur reply.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try this one

Code: Select all

<html>
	<head>
		<title>javascript[] test</title>
		<script type="text/javascript">
			function yadda() {
				oSource = document.getElementById("idsource");
				oTarget = document.getElementById("idtarget");
				for(i=oSource.length-1; i>0; i--) {
					if (oSource.item(i).selected) {
						oTarget.add(oSource.item(i), null);
					}
				}
			}
		</script>
	</head>
	<body>
		<div>
			<select id="idsource" multiple="muliple">
				<option>a</option>
				<option>b</option>
				<option>c</option>
				<option>d</option>
			</select>
			<br />
			<button onclick="javascript:yadda()">transfer</button>
		</div>
		<form method="GET" action="test.php">
			<div>
				<select id="idtarget" name="select2[]" multiple="muliple">
				</select>
				<br />
				<input type="submit" />
			</div>
		</form>
	</body>
</html>
and as test.php

Code: Select all

<html>
	<head>
		<title>...</title>
	</head>
	<body>
<?php
if ( isset($_GET['select2']) && is_array($_GET['select2']) ) {
	foreach($_GET['select2'] as $s2) {
		echo 'selected:', $s2, "<br />\n";
	}
}
?>
	</body>
</html>
adeelzia
Forum Newbie
Posts: 22
Joined: Thu Jul 06, 2006 5:31 pm

Post by adeelzia »

Bravo Man! Sorry for a late reply but Mr.Volka is brilliant, thanks again. Got exactly what I needed.
Post Reply