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 guysVolka Wrote: So why can't the select element have the name select2[] ?
Store value from query string into an array
Moderator: General Moderators
not true.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
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");
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.
try this oneand as test.php
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>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>