function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
qqragoon
Forum Newbie
Posts: 17
Joined: Wed Nov 15, 2006 6:17 pm

function

Post 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!
blackbeard
Forum Contributor
Posts: 123
Joined: Thu Aug 03, 2006 6:20 pm

Post by blackbeard »

Unless you want to reload the page every time a change is made, you'll have to use javascript.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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.
blackbeard
Forum Contributor
Posts: 123
Joined: Thu Aug 03, 2006 6:20 pm

Post by blackbeard »

Why would you use AJAX in a scenario like this? Plain javascript would seem the simpliest choice here.
User avatar
louie35
Forum Contributor
Posts: 144
Joined: Fri Jan 26, 2007 8:40 am
Location: Dublin
Contact:

Post by louie35 »

as much as i love ajax this is too simple not to use plain javascript.
qqragoon
Forum Newbie
Posts: 17
Joined: Wed Nov 15, 2006 6:17 pm

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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. ;)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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?
qqragoon
Forum Newbie
Posts: 17
Joined: Wed Nov 15, 2006 6:17 pm

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Why hide the formula?
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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? :roll:
Post Reply