Page 1 of 1
function
Posted: Mon Feb 12, 2007 1:24 pm
by qqragoon
I am trying to write a function to calculate values and display them into text field of a form DYNAMICLY. Which means while data in a text field changes, another text field changes accordingly based on the formula. I know how to do this with Javascript. Write a function and call it when text box changes. However, in this method, the formula is exposed to the public. It can be seen from VIEW SOURCE. Is there any way to do this in php? so that it executes the function on server side. Thanks in advance!
Posted: Mon Feb 12, 2007 1:34 pm
by blackbeard
Unless you want to reload the page every time a change is made, you'll have to use javascript.
Posted: Mon Feb 12, 2007 1:35 pm
by infolock
yep, but you would need to use ajax methods or remote scripting methods. php cannot do it unless the server is called, and the only way to do that is one of the 2 i just gave ya.
Posted: Mon Feb 12, 2007 1:50 pm
by blackbeard
Why would you use AJAX in a scenario like this? Plain javascript would seem the simpliest choice here.
Posted: Mon Feb 12, 2007 2:01 pm
by louie35
as much as i love ajax this is too simple not to use plain javascript.
Posted: Mon Feb 12, 2007 3:39 pm
by qqragoon
Thanks for all your guys' input. I understand this is a simple task, plain javascript is the right way to go. However, the security has the priority. Here is another way i can think of. Use js file as a header file and put it in another location that requires authentication. I think that should do it.
Posted: Mon Feb 12, 2007 3:52 pm
by feyd
The algorithm doesn't need to be secure, does it? It's pretty silly if it does. If you're wanting it to be authoritative in some end goal calculation, submit them back to the server and have it perform the calculation. Don't assume the data you are getting as resultant is in fact correct.

Posted: Mon Feb 12, 2007 3:54 pm
by RobertGonzalez
As long as you are bringing in a Javascript library, your formula will not be hidden. I suspect that is what you are were getting at by your original post. Are you trying to keep your formula from being seen?
Posted: Mon Feb 12, 2007 4:07 pm
by qqragoon
Everah wrote:As long as you are bringing in a Javascript library, your formula will not be hidden. I suspect that is what you are were getting at by your original post. Are you trying to keep your formula from being seen?
Yes, that was the objective.
Posted: Mon Feb 12, 2007 4:21 pm
by RobertGonzalez
Then you are going to have calculate on the server. That is the only way to make sure your calculation formula is not seen.
Posted: Mon Feb 12, 2007 11:01 pm
by feyd
Why hide the formula?
Posted: Wed Feb 14, 2007 11:11 am
by infolock
blackbeard wrote:Why would you use AJAX in a scenario like this? Plain javascript would seem the simpliest choice here.
because....the poster said he wanted to know if it was possible to do this with php?
