"R.G. Vervoort" wrote:
is it possible to declare a variable in the onchange event of a <select> and
use it later in php
I would like to put the value of the selected option (in <select>) in a
variable and later when i activate a php function use this variable
Looks inpossible but who knows maybe it is possible
roy
<select onchange="sendToServer(this);">
<script type="text/javascript">
function sendToServer(sel) {
(new Image()).src = 'path/to/your/file.php?theValue=' +
sel.options[sel.selectedIndex].value;
}
</script>
You have no way of knowing whether or not the call succeeded using this method.
You can achieve some degree of error checking by having the file.php retrieve
and send an image of specific dimensions back to the client, then you could
interrogate those dimensions to determine whether the call succeeded or not:
<script type="text/javascript">
function sendToServer(sel) {
var i = new Image();
i.onload = imgOnLoad;
i.onerror = imgOnError;
i.src = 'path/to/your/file.php?theValue=' +
sel.options[sel.selectedIndex].value;
// file.php would do whatever with the value passed and then
// return an image that is 10 pixels wide if everything succeeded
// and an image that is 20 pixels wide if anything failed
}
function imgOnLoad() {
if (this.width == 10) {
alert('Success');
} else if (this.width == 20) {
alert('Failure');
}
}
function imgOnError() {
alert('Call to set theValue on the server failed');
}
</script>
--
| Grant Wagner <gw*****@agricoreunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
*
http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
*
http://www.mozilla.org/docs/web-deve...upgrade_2.html