I want to call a function in a separate .php file when I click on a hyperlink (href is NOT php file). My .htm code looks something like this: (I'm testing the code with <h1> or else I won't see the server's response.) <html> <body> <form name="coolform" method="get" action="test.php?q=PRE_SET_PARAM"> <h1 onclick="document.coolform.submit()"> Random Destination </h1> </form> </body> </html> And test.php looks like this: <html> <body> <?php echo $_GET['q']; ?> </body> </html> My only guess as to why this doesn't work is that it looks for test.php?q=PRE_SET_PARAM instead of test.php because ?q= can only be added at submission. How can I pass variable q to test.php
That should work, but you could also try using a hidden named q. <html> <body> <form name="coolform" method="get" action="test.php"> <input type="hidden" name="q" value="PRE_SET_PARAM" /> <h1 onclick="document.coolform.submit()"> Random Destination </h1> </form> </body> </html> HTML: Does the form currently submit at all. I didn't think that an h1 onclick is supported by every browser. You may need to format a submit button to look text if it isn't well supported.