What I am trying to figure out how to use JavaScript to Show/Hide PHP scripts.
JavaScript:
<script type="text/javascript">
function showhide(id){
if (document.getElementById){
obj = document.getElementById(id);
if (obj.style.display == "none"){
obj.style.display = "";
} else {
obj.style.display = "none";
}
}
}
</script>
Body Code:
<?php
echo "<a href='javascript:showhide('delivery.php');'>Show/Hide Delivery options</a>";
require "delivery.php" ?>
Any ideas on why/how I could get this to work?
Any help is appreciated!
JavaScript is Client-side, that means it is executed on your PC, after the website has been downloaded from the server.
PHP is server-side, that means it is executed on the Server computer, and then it sends a pure HTML page to your PC.
That’s why its not possible. You have to use PHP to do that, using some variables. Otherwise you can use javascript/ajax to send a request to the server, which then sends the new information back to the client, which can then update the page.
But its better to just do it in PHP like this:
‘some_var’ can be send to the PHP page with a form like this:
If you type “blah” into the text field and send it, the page will show ‘somefile.php’, but if you type “nyah” it will show ‘some_other_file.php’s contents instead.
Hope this helps.