Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Dear all
I have javascript variable(var count=...)
and php variable ($lCount).
I need perform: lCount=count,but how ?
Thanks for help

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.

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 ?

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.

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).

![]() |
![]() |
![]() |

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