Jump to content

Call a php function from html


optikalefx

Recommended Posts

How would i go about doing this?

 

<?

function phpFunction($str) {

echo $str;

}

 

<form>

<input type="text" name="text" onKeyUP="phpFunction(this.value);"

</form>

 

 

i know theres a lot wrong with that, because that is just a guess.

 

but if i save this thing as like  xxx.php

shouldnt i be able to call a function on the fly like that?

 

(the goal is to have php search a database on each keystroke)

Link to comment
https://forums.phpfreaks.com/topic/64768-call-a-php-function-from-html/
Share on other sites

nope

try this

<?php

include('phpinc.php');//all statements end with ;
echo'
<html>
<form>
<input type="text" name="text" onKeyUp="phpFunction(value of $str);">//are u sure you wanna use input type
</form>
</html>
';
?>

and then in phpinc.php


<?php
function phpFunction($str) {
echo $str;//you can do more than echo 
}

?>

and in future, try using the [ code ] [/code ] without the spaces, makes it easier to read

*UPDATED*
PS be sure you have the files in the same folder  or else your include wont work and will need to be changed

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.