0

I have code which passes php variable to another page on my site:

echo'<a class="btn btn-danger" style="margin-left:10px;width:120px;float:left;"  href="fullsizemarket.php?imageid=',$imageid,'&action=removed">Remove from Cart</a>';

I am able to retrieve the php variable $imageid by the following:

$imageid = htmlentities($_GET['imageid']);

I want to also pass in this code the value of a javascript variable. The variable is set in an earlier part of the code as follows:

     var rowcount

I don't know how to pass var rowcount in the same echo code as I pass $imageid. What is the code to do this?

7
  • If the variable is defined in Javascript, then it is already too late, because your PHP code runs before the page arrives at the user, and before the Javascript runs. Of course, if you absolutely have to do this, you could send the data to a PHP page once the page has loaded, using AJAX. Commented Aug 17, 2012 at 4:03
  • To clarify, it would work like this: User requests page -> PHP runs -> user gets page with AJAX code in it -> AJAX runs and requests page in the background -> PHP runs and receives variable. Commented Aug 17, 2012 at 4:06
  • @LonelyWebCrawler I don't know ajax. Would this be hard to implement? Commented Aug 17, 2012 at 4:06
  • ...or without Ajax you can add a click handler that changes the href attribute to include the current value of rowcount. Commented Aug 17, 2012 at 4:07
  • @user1605871 No, AJAX is really simple if you use jQuery (which you should). Once you have jQuery set up, you can use the $.get() function to request a page and send it the contents of that variable. However, you should think hard about whether this is really necessary, or if you can restructure your code so that PHP does not the variable from Javascript. Here's a link to the function: api.jquery.com/jQuery.get Commented Aug 17, 2012 at 4:09

1 Answer 1

1

How bout following:

echo 
"<a class='btn btn-danger' 
    style='margin-left:10px;width:120px;float:left;' 
    href='fullsizemarket.php?imageid=$imageid&action=removed&rowcount='
    onclick = \" this.setAttribute('href', this.getAttribute('href')+rowcount) \"
 >Remove from Cart</a>";
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.