473,805 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

declaring variable in onchange to use in php

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
Jul 23 '05 #1
2 2612
On Thu, 15 Apr 2004 23:45:42 +0200, R.G. Vervoort
<ro**********@r oyvervoort.nl> 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


You'll have to send it to the server using either the search (query) part
of the URI, or POSTed in a form. Server-side languages cannot obtain the
values of script variables directly as that data only exists on the client.

Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #2
"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="sendT oServer(this);" >

<script type="text/javascript">
function sendToServer(se l) {
(new Image()).src = 'path/to/your/file.php?theVal ue=' +
sel.options[sel.selectedInd ex].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(se l) {
var i = new Image();
i.onload = imgOnLoad;
i.onerror = imgOnError;
i.src = 'path/to/your/file.php?theVal ue=' +
sel.options[sel.selectedInd ex].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*****@agrico reunited.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
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
7532
by: R.G. Vervoort | last post by:
I am using a javafunction (onclick in select) in which i am calling a function in php (thats why i send this to both php and javascript newsgroups). in the onclick i call the function "Place_Selected" with the value from the select (naam_keuze.value) in the function the value becomes the $zoek_id and searches in the database for the record with the id of $zoek_id
3
9020
by: Paul Eghbal | last post by:
Hi all, I'm trying to use the following script: <script language="javaScript"> function setrepto(){ document.aForm.repno.value = document.aForm.rep.options.value; } </script>
8
1513
by: xxgeorge | last post by:
hi all, I'm writing a function that, say, loop through input fields in a form and set default values to it. Some fields are dependent thus I have some onChange scripts to kick off corresponding actions to those fields. <form name="test"> <input type="text" name="text1">
4
6317
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by the choice from the drop down box. Something like: <form name="populatefrm" id="contactfrm" method="post"
2
2167
by: joltman | last post by:
OK, this is kind of hard to explain, so I'll do my best: I have a form where I have a row where there could be multiple entries, so I have a link where it will dynamically add another row like it, and this can happen as many times as you click on the link. This row consists of 2 drop-down boxes. Depending on the selection of the first drop-down box, the second drop-down box is either disabled or enabled. The problem is on these dynamically...
1
2868
by: Maarten Terlingen | last post by:
Sample: ClassA: ClassB ClassB: ClassC ClassA x = new Class C I want to know the declaring type of C. x.GetType() returns C x.GetType().BaseType returns B x.GetType().BaseType.BaseType returns A, but I don't know the depth in my
5
3270
by: Daz | last post by:
Hi everyone. Another simple question which should hopefully warrent a simple answer. I would like a function to be run whenever a variable is updated. I have tried binding the onchange event to it, and it doesn't work. I think I understand why, however, I would like to know if there is anything that I can bind to my variable that will fire the specified function whenever the value changes.
8
7524
by: SM | last post by:
I've always wonder if there is diference when declaring and initializing a varible inside/outside a loop. What's a better practice? Declaring and initializing variables inside a loop routine, like this: for(var i=0; i<list; i++) { var name = list; }
0
377
by: David C | last post by:
I am getting this error in the Databound event of a GridView and I am having a difficult time debugging. I do not get the error on every record that I edit in the GridView. The error is occurring on the lines that start with varCtl. (for example varCtl.CssClass = "Hide"). The other thing that is strange is that it occurs when I click the Edit button on the GridView and yet the error is pointing to a line in the code that only gets...
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10607
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10104
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9182
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5541
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4317
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.