0

I am sure this should be easy but I ahve been going crazy trying to get it to work:

return '<img border="0" src="'.$args['Image URL'].'?amount='.$args['invoiceAmount'].'&trans_id='.$args['invoiceNumber'].'&jrox_svalue_1=Sitename:javascript:document.write (sitename);" width="1" height="1">';

Essentially I need to inject the javascript varialbe "sitename" into the querystring value (jrox_svalue_1)for the image.

jrox_svalue_1=Sitename:javascript:document.write (sitename);

Any help would be apprecaited.

2
  • 2
    PHP is Server Side, javascript is client side. You can't get the javascript values in PHP. Commented Dec 18, 2010 at 22:58
  • You could manipulate the image on the client side though after PHP has sent it to the browser, and append that value to the source. Commented Dec 18, 2010 at 23:02

2 Answers 2

2

This should do the trick:

<script>
document.write("<?php echo '<img border="0" src="' . $args['Image URL'] . '?amount=' . $args['invoiceAmount'] . '&trans_id=' . $args['invoiceNumber'] . '&jrox_svalue_1=' ?>" + sitename + '" width="1" height="1">');
</script>
Sign up to request clarification or add additional context in comments.

4 Comments

That php would get pushed to the page, but it would not get executed. PHP is processed at the server side. Javascript is processed at the client.
Well I wasn't absolutely wrong, but now that I took a closer look at what you had I realized what you are doing. At first glance I whought you were actually trying to write the php to the page using javascript. After looking closer I realized that the php would get processed at the server side, and then javascript would write the image.
looks like you so his low rep and immediately gave the boiler-plate 'you're misunderstanding server/client side' argument. He was entirely correct. Both understood that the PHP evaluation happens first followed by javascript's, and even gave all the single quotes, double quotes, php . concats, and js + concats entirely correctly. good answer sexyprout!
@jon_darkstar: No, I didn't care about his rep at all. I just misread the code snippet.
0

Hope this would help

<img id="jroxImg" src="'.$args['Image URL'].'?amount='.$args['invoiceAmount'].'&trans_id='.$args['invoiceNumber']." width="1" height="1"> 


<script type="text/javascript">

 var jroxImgObj=document.getElementById('jroxImg');

 var jroxImgSrc=jroxImgObj.getAttribute('src');

 jroxImgSrc+="&jrox_svalue_1="+siteName;//document.location ??

 jroxImgObj.setAttribute('src',jroxImgSrc);

</script>

2 Comments

The only caveat is that you likely would not want to try and get the image from your partial query string first, so you might need to tweak this answer.
WOW WOW WOW.. What an amazing site! Thanks heaps guys.. Worked a treat.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.