sssmith Posted April 3, 2012 Share Posted April 3, 2012 I know this is 'old stuff', but I am new to this and very frustrated- I am trying to pass a variable to a new url via an html onclick event, and failing. I have found several posts about it but the code posted in those posts does not work when I try it. I have struggled mightly with this. Here is my code: first an echo of two versions of the onclick statement, and two versions of the actual button code. The echos from the two versions appear identical, but the first button with no variable works while the second using a variable results in no action. Can anyone point me in the direction of a solution? I suspect there is some simple principal I am missing relating to parsing strings. <?php echo "window.location.href='ManageTitles.php?dog=2'"; echo "\n" ; echo "window.location.href='ManageTitles.php?dog={$row_rsDogsowned['idDogInfo']}'"; ?> <form methd="POST" Name="form3" action="<?php echo $editFormAction; ?>"> <input type="button" value="works" onclick="window.location.href='ManageTitles.php?dog=2'" /> <input type=button onclick="window.location.href='ManageTitles.php?dog={$row_rsDogsowned['idDogInfo']}'" value="fails" /> </form Quote Link to comment https://forums.phpfreaks.com/topic/260298-passing-variable-via-html-button-to-new-url/ Share on other sites More sharing options...
mreish Posted April 3, 2012 Share Posted April 3, 2012 I might not understand what you're trying to do. The button labeled "works" sure seems to pass an argument to ManageTitles.php just fine. Remember that in ManageTitles.php you nee dot use the $_GET super global to read that argument. I can shoot you as sample if you like. Or, I don't understand what you're trying to accomplish. Edit: Ah, think I know what you're missing. Try this for the 'fails' button: <input type=button value="fails" onclick="window.location.href='ManageTitles.php?dog=<?php echo $row_rsDogsowned['idDogInfo']; ?>'" /> Quote Link to comment https://forums.phpfreaks.com/topic/260298-passing-variable-via-html-button-to-new-url/#findComment-1334170 Share on other sites More sharing options...
sssmith Posted April 4, 2012 Author Share Posted April 4, 2012 Thank you very much- it works perfectly. Quote Link to comment https://forums.phpfreaks.com/topic/260298-passing-variable-via-html-button-to-new-url/#findComment-1334238 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.