calling php function within javascript

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
sh33p1985
Forum Commoner
Posts: 78
Joined: Thu Mar 11, 2004 9:22 am

calling php function within javascript

Post by sh33p1985 »

is this possible?

would like to call a function from a .php file and return the string from the function to the javascript

e.g.

Code: Select all

<script language="javascript" type="text/javascript"> 
<!-- 
     function functionName() { 
          string = PHPfunction(document.formname.fieldname.value);
          //do stuff
     } 
// --> 
</script>
.php file:

Code: Select all

function PHPfunction($string){
      //do stuff    
     return $string;
}
would like to do something in php to the string before the javascript parses it.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

You could call back to the server with something AJAXy, but it'd be a bit pointless. Why not just use JavaScript?
sh33p1985
Forum Commoner
Posts: 78
Joined: Thu Mar 11, 2004 9:22 am

Post by sh33p1985 »

im attempting to hash a string and then use it before a form is sumitted.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

sh33p1985 wrote:im attempting to hash a string and then use it before a form is sumitted.
Why can't you hash it with JavaScript?
sh33p1985
Forum Commoner
Posts: 78
Joined: Thu Mar 11, 2004 9:22 am

Post by sh33p1985 »

didnt know that was possible! *google inc*

cant say im that knowledgable with javascript dont use it much.
sh33p1985
Forum Commoner
Posts: 78
Joined: Thu Mar 11, 2004 9:22 am

Post by sh33p1985 »

found the md5.js file, and got it working!
Post Reply