Computing.Net > Forums > Programming > javascript value for PHP variable

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

javascript value for PHP variable

Reply to Message Icon

Name: nnn
Date: October 23, 2002 at 23:29:18 Pacific
OS: linux
CPU/Ram: 1
Comment:

Dear all
I have javascript variable(var count=...)
and php variable ($lCount).
I need perform: lCount=count,but how ?
Thanks for help



Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: October 24, 2002 at 00:07:56 Pacific
Reply:

I don't do PHP, but I believe that it is a server side language (meaning, it runs on the web server BEFORE the page is sent to the browser) and I know that Javascript is a client side language (it runs after the page is loaded into the client).

I use JSP, which is server side, and the only way to compare a JSP value with a javascript value is to have the JSP place its value into the javascript code so that when the javascript executes, it uses the value.

So on the server the could would look something like

function doit() {

if ([% lCount %] == count) {
....
}


The [% lCount %] tells the JSP code to insert the JSP value of lCount. By the time the page reaches the browser, the browser doesn't see the JSP code, it'll see
(Actually those should be greater than, less than symbols rather than brackets, but this forum doesn't like when you use them)

function doit() {

if (123 == count) {
....
}


I would guess that you could do something similiar with PHP. You need to find how to insert a PHP variable's value into the javascript code.


0

Response Number 2
Name: nnn
Date: October 24, 2002 at 22:34:50 Pacific
Reply:

Thank you very much :)
I know how insert a PHP variable's value into the javascript code, but this is not enough.
My task:
there are 2 "select", filled from the MySQL;
first "select" has "onChange" function, defined in javascript;
i need use selected value from first "select" like a part of MySQL query for refilling second "select";
but this value is a javascript variable, and all this must be done before "submit";
Do you have any idea ?


0

Response Number 3
Name: Cerj (by cerj)
Date: October 28, 2002 at 04:19:51 Pacific
Reply:

There are two solutions.

1. in the onChange of first select you have to submit your form. Then on the server you retrieve the value and use it to do your second select and display data.


2. you may use javascript arrays and store all possible values. In the onChange of first select you call a function that you have to write that will populate the second select list with the corresponding data.

The choice between the two methods depends on the quantity of data that have to be shown int the lists.



0

Response Number 4
Name: JSLover
Date: October 29, 2002 at 01:14:38 Pacific
Reply:

I have an interesting thing to try...instead of submitting & refreshing the current page you could submit to a new window & have that window use javascript to update the 2nd select. & another option I just thought of while typing this (& just now noticed this is what the last post said in a different way that I didn't realize the 1st time) is enum all possible select1 options & store that on the page in JS & then JS can access it without submitting each time. This is probably to involved for this board but I'd like to explore this somehow. I would post example code but I always debug code I post & that would take me forever but I'd like to work with you & try it. Actually I have my own server to test on so I'll report back. Er um but I do need the php it need's to interact with cuz I'm not good with server-side languages (minor changes but not from scratch).


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: javascript value for PHP variable

Value of a variable in sed command www.computing.net/answers/programming/value-of-a-variable-in-sed-command/17860.html

defult value for the parameter www.computing.net/answers/programming/defult-value-for-the-parameter/15346.html

Hex value for hkey_current_user? www.computing.net/answers/programming/hex-value-for-hkeycurrentuser/10714.html