Jump to content

Passing variable via html button to new url


sssmith

Recommended Posts

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

 

Link to comment
Share on other sites

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']; ?>'" />

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.