1 / 4
Jan 2009

I am a fairly inexperienced, renegade programmer and know only the basics of javascript and php, so this may be a simple question...



I am trying to incorporate logical if-then statements to create a thank you page that reports a well-formatted customized invoice, reporting only the data applicable to each customer's purchase. In other words, the invoice for a free file download does not need to report the price or shipping address, whereas the invoice for a tangible good would report all this information.



I am more familiar with javascript, so I wrote myself a code in javascript to trigger events on the thank you page, based upon the order data - but I cannot seem to figure out how to get my javascript code to recognize this order data... here's a sample of my logic:



<script>

var gross = document.getElementById(gross);

if (gross==null)

{document.write("<b>FREE DOWNLOAD</b>")}

else

{document.write("<b>ORDER DETAILS</b>")}

</script>



of course, this doesn't work because I totally just pulled that .getElementById command out of the air... but I am beginning to wonder whether this kind of thing is possible using javascript or whether I will have to try php instead. or maybe I am just missing something simple.

  • created

    Jan '09
  • last reply

    Jan '09
  • 3

    replies

  • 1.3k

    views

  • 2

    users

  • 1

    link

After reading more into this issue, I understand I'm going to have to use a php function to parse my page for these variables. Could someone explain to me why this doesn't work?



<script type="text/javascript">

var gross = "<?php print $GET['mcgross']; ?>";

if (gross==null)

{document.write("<b>OUTPUT 1</b>")}

else

{document.write("<b>OUTPUT2</b>")}

</script>



The php print function is not returning any variables...

E-junkie publishes your code "as it is". Browser can parse the client side code i.e. JavaScript but it can't parse PHP.



The only parsing E-junkie does to your code before publishing it is to replace "template variables" with their respective values.



So, you code should be -



<script type="text/javascript">

var gross = "[%total%]";

if (gross==null)

{document.write("<b>OUTPUT 1</b>")}

else

{document.write("<b>OUTPUT2</b>")}

</script>



PS: I am assuming your are using this code on "common" thank you page.



For the complete list of template variables that you can use in the thank you page, please see http://www.e-junkie.com/ej/help.customization.htm

Hi, thanks for your help! I thought I had tried that one already, but I was apparently mistaken. Everything is working perfectly now!