phpQuestioner Posted August 10, 2007 Share Posted August 10, 2007 I have one php page with roughly 10 functions in it and I have put this page in a include in a application/x-javascript. The include works, but it only pulls the first function from the include. I want to be able to specify the function I want to pull from the include in put into a specific area of the javascript. My code is below; does any know what I mean and/or how to do this? <?php header("Content-type: application/x-javascript"); //make asc javascript function echo "function makeascend()\n {\n document.getElementById('vehicles').innerHTML='"; ?> <?php include("sort.php"); ?> <?php echo "'\n }\n"; ?> Link to comment https://forums.phpfreaks.com/topic/64295-how-to-include-php-function-from-php-file-into-applicationx-javascript-file/ Share on other sites More sharing options...
lemmin Posted August 10, 2007 Share Posted August 10, 2007 Why don't you just include the whole thing. The php is server side, the client doesn't have to download more if all your functions are available. Link to comment https://forums.phpfreaks.com/topic/64295-how-to-include-php-function-from-php-file-into-applicationx-javascript-file/#findComment-320534 Share on other sites More sharing options...
phpQuestioner Posted August 10, 2007 Author Share Posted August 10, 2007 yeah - i tried that; like this: <?php include("sort.php"); ?> <?php header("Content-type: application/x-javascript"); //make asc javascript function echo "function makeascend()\n {\n document.getElementById('vehicles').innerHTML='myphpfunction()';\n }\n"; ?> But that did not work; the php function was not included; just spit out this: function makeasend() { document.getElementById('vehicles').innerHTML='myphpfunction()'; } Link to comment https://forums.phpfreaks.com/topic/64295-how-to-include-php-function-from-php-file-into-applicationx-javascript-file/#findComment-320554 Share on other sites More sharing options...
lemmin Posted August 10, 2007 Share Posted August 10, 2007 That is because it is litteraly a string. I really don't know what you are trying to do. does 'myphpfunction()' return a string that you put in the innerHTML of the element? If so, change the line from: document.getElementById('vehicles').innerHTML='myphpfunction()';\n to: document.getElementById('vehicles').innerHTML='" . myphpfunction() . "';\n If it wasn't including the function, it would give you an error when it tries to execute it. Link to comment https://forums.phpfreaks.com/topic/64295-how-to-include-php-function-from-php-file-into-applicationx-javascript-file/#findComment-320591 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.