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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.