|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Variables between Javascript and ASP
I was wondering if anyone out there knows how i can pass a variable from my JavaCsript function to my ASP function.
I have a list from which I call a javascript function with onChange(javascript function). Inside that function, i want to pass a variable to an ASP function which will use it in a SQL query. I have tried everything i can imagine but to no avail. If that is not possible does anyone know how i can accomplish this in another way? I mean... can i call the ASP function directly from my onChange(asp function)? Or does an onChange require a script? Thanks in advance for any suggestions that can be offered. |
|
#2
|
||||
|
||||
|
Hi,
I already answered this for you, but I wanted to post the answer as well: You can't pass javascript variables to ASP functions. The ASP functions run server-side and have completed their execution once the page has loaded and the javascript is ready to be run. |
|
#3
|
||||
|
||||
|
And here's a little more info about mixing server-side ASP (which gets processed first) with client-side JavaScript.
It's easy to use the value of a VBScript variable in javascript: document.writeln('<%= MyVBScriptVariable %>'); Or here is an example which puts the value of a VBScript variable into a JavaScript alert box: Response.Write "<script language='JavaScript'>alert('The value is " & MyVBScriptVariable & "');</script>" But to send the value of a JavaScript variable to VBScript, well that's another story. You could have the JavaScript fill in a hidden form field and then post the form. That way VBScript can pick up the value of the hidden form field with Request.Form("MyFieldName")
__________________
J. Paul Schmidt www.Bullschmidt.com - Freelance Web and Database Developer www.Bullschmidt.com/DevTip.asp - Classic ASP Design Tips |
|
#4
|
|||
|
|||
|
This is just a thought but maybe you can use it. (Even bothered to signup cause i was just looking for something myself).
If you make your ASP page and you implement your javascript in it.You could insert a hidden textfield <input type="hidden" name="javascriptvariablename" value="javascriptvariablevalue"> Then you should submit the page to itself (leave the "action" property in your form tag empty). Next put something in your asp code where you check if "server.request(javascriptvariablename) (i belive you request it that way, long time since i worked with asp i prefer php) you should do his to determine if it is the first time or the second time you load the page. Then if that variable is not empty you can process it trough your query or whatever you want to do with it. |
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > Variables between Javascript and ASP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|