optikalefx Posted August 14, 2007 Share Posted August 14, 2007 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) Quote Link to comment https://forums.phpfreaks.com/topic/64768-call-a-php-function-from-html/ Share on other sites More sharing options...
uwannadonkey Posted August 14, 2007 Share Posted August 14, 2007 i think what you mean is PREdetermine a function, and then use the include('filename'); to bring it up for every page? and ur code is missing a ?> Quote Link to comment https://forums.phpfreaks.com/topic/64768-call-a-php-function-from-html/#findComment-323077 Share on other sites More sharing options...
d22552000 Posted August 14, 2007 Share Posted August 14, 2007 he did say it was a guess and it was incomplete. I suggest <?PHP instead of <?. Not all servers allow short_tag Quote Link to comment https://forums.phpfreaks.com/topic/64768-call-a-php-function-from-html/#findComment-323079 Share on other sites More sharing options...
uwannadonkey Posted August 14, 2007 Share Posted August 14, 2007 yea, i was also about to write that, lol Quote Link to comment https://forums.phpfreaks.com/topic/64768-call-a-php-function-from-html/#findComment-323083 Share on other sites More sharing options...
optikalefx Posted August 14, 2007 Author Share Posted August 14, 2007 ok soo.. <html> include('phpinc.php') <form> <input type="text" name="text" onKeyUp="phpFunction(this.value);"> </form> </html> and then in phpinc.php <?php function phpFunction($str) { echo $str; } ?> will that work? Quote Link to comment https://forums.phpfreaks.com/topic/64768-call-a-php-function-from-html/#findComment-323093 Share on other sites More sharing options...
uwannadonkey Posted August 14, 2007 Share Posted August 14, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/64768-call-a-php-function-from-html/#findComment-323096 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.