Page 2 of 2

Posted: Wed Aug 23, 2006 1:55 pm
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]

Posted: Wed Aug 23, 2006 2:57 pm
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");

Posted: Wed Aug 23, 2006 4:10 pm
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.

Posted: Wed Aug 23, 2006 5:22 pm
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>

Posted: Sun Aug 27, 2006 2:42 pm
by adeelzia
Bravo Man! Sorry for a late reply but Mr.Volka is brilliant, thanks again. Got exactly what I needed.