Page 1 of 1

calling php function within javascript

Posted: Wed Nov 01, 2006 6:12 am
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.

Posted: Wed Nov 01, 2006 6:17 am
by onion2k
You could call back to the server with something AJAXy, but it'd be a bit pointless. Why not just use JavaScript?

Posted: Wed Nov 01, 2006 6:19 am
by sh33p1985
im attempting to hash a string and then use it before a form is sumitted.

Posted: Wed Nov 01, 2006 6:22 am
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?

Posted: Wed Nov 01, 2006 6:23 am
by sh33p1985
didnt know that was possible! *google inc*

cant say im that knowledgable with javascript dont use it much.

Posted: Wed Nov 01, 2006 6:27 am
by sh33p1985
found the md5.js file, and got it working!