JackTheRussel
Programmer
Hi.
I have multiselect listbox on my web-page.
Now I try to give selected listbox values to the javascript function (GetValues) when button is pushed.
I found two function on web, which print values to the alert-box when button is pushed (getSelected and outputSelected)
I changed alert-function to GetValues function, which call php-script (test.php) which print values to the screen.
Now when I push the button test.php always print 0 to the screen. I don't know how I can get this work.
Here is my functions
And here are test.php
And here is listbox and button code
If you have better solution I am more than glad to hear it.
The main purpose is to get values to the php-script.
Not to print values to the screen.
Help are needed.
I have multiselect listbox on my web-page.
Now I try to give selected listbox values to the javascript function (GetValues) when button is pushed.
I found two function on web, which print values to the alert-box when button is pushed (getSelected and outputSelected)
I changed alert-function to GetValues function, which call php-script (test.php) which print values to the screen.
Now when I push the button test.php always print 0 to the screen. I don't know how I can get this work.
Here is my functions
Code:
function getSelected(opt) {
var selected = new Array();
var index = 0;
for (var intLoop = 0; intLoop < opt.length; intLoop++) {
if ((opt[intLoop].selected) ||
(opt[intLoop].checked)) {
index = selected.length;
selected[index] = new Object;
selected[index].value = opt[intLoop].value;
selected[index].index = intLoop;
}
}
return selected;
}
function outputSelected(opt) {
var sel = getSelected(opt);
var strSel = "";
for (var item in sel)
strSel += sel[item].value + "\n";
Hae(strSel);
}
function GetValues(strSel) {
var strURL="test.php?Res="+strSel;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('testdiv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
And here are test.php
Code:
<?php
$Res=intval($_GET['strSel']);
echo "<h1>$Res</h1>"; //PRINTS ALWAYS 0 TO SCREEN
?>
And here is listbox and button code
Code:
<SELECT NAME="multistore" SIZE=3 MULTIPLE>
<OPTION VALUE="Computer" SELECTED>Computer</OPTION>
<OPTION VALUE="Bookstore">Book Store</OPTION>
<OPTION VALUE="MailOrder" SELECTED>Mail Order</OPTION>
</SELECT>
<INPUT TYPE=BUTTON VALUE="Selected List Items"
ONCLICK="outputSelected(this.form.multistore.options)">
If you have better solution I am more than glad to hear it.
The main purpose is to get values to the php-script.
Not to print values to the screen.
Help are needed.