How could I get a php variable into some javasript code! Please :-)

Discussion in 'HTML & Website Design' started by mike33pt, Apr 4, 2009.

  1. #1
    I can grab the google conversion code using php. The header can send "?gcode=123456" I then want to get the conversion code "123456" to replace "xxxxxxxxxxxx" below.

    I tried putting <?php echo $gcode;?> in place of xxxxxxxxxxxx but obviously that is not going to work. But it explains what I'm trying to achieve.

    Any ideas anyone?

    Thanks in advance

    
    <script language="JavaScript" type="text/javascript">
    <!--
    var google_conversion_id = xxxxxxxxxxxx;
    var google_conversion_language = "en_GB";
    var google_conversion_format = "3";
    var google_conversion_color = "ffffff";
    var google_conversion_label = "YQ4tCI-kjhgytfytgg";
    //-->
    </script>
    <script language="JavaScript" src="http://www.googleadservices.com/pagead/conversion.js">
    </script>
    <noscript>
    <img height="1" width="1" border="0" src="http://www.googleadservices.com/pagead/conversion/1053595815/?label=YQ4tCI-kjhgytfytgg&amp;guid=ON&amp;script=0"/>
    </noscript>
    Code (markup):
     
    mike33pt, Apr 4, 2009 IP
  2. mahendras

    mahendras Peon

    Messages:
    597
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I can help you.
    Create a Form on the page and put a Hidden field in it.
    Assign your PHP variable value to the hidden field.
    Close the form.
    Then after under that form you can write your javascript and use that hidden field ( where you had variable value) using Document.Form.formname.fieldname.value.......

    I hope this helps.
     
    mahendras, Apr 4, 2009 IP
  3. mike33pt

    mike33pt Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    So I made the form:

    
    <form action="" method="post" name="gcode">
    <input name="gcode" type="hidden" value="<?php echo $vargcode;?>">
    </form>
    
    Code (markup):
    On viewing the source I now see ?gcode as a form value

    Still trying to figure out how to mash these together:

    Document.Form.formname.fieldname.value.......

    var google_conversion_id = xxxxxxxxxxxx;

    I just cant see how I get the javascript part to display the new form value.

    Would appreciate your help again.

    Thank you

    Mike
     
    mike33pt, Apr 4, 2009 IP
  4. mike33pt

    mike33pt Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    After 40 minutes I'm getting nowhere fast

    When I send the header through the url and I view my source page I see that this value="<?php echo $vargcode;?>" is updated with what I sent, cool.

    But I just cannot see how to replace "xxxxxxxxxxxxx" below with this new form value.

    
    <form action="" method="post" name="form1">
    <input name="value1" type="hidden" value="<?php echo $vargcode;?>">
    </form>
    <!-- Google Code for Sale of HowtoManifestAffiliateWealth Conversion Page -->
    <script language="JavaScript" type="text/javascript">
    <!--
    var google_conversion_id = xxxxxxxxxxxxx;
    var google_conversion_language = "en_GB";
    var google_conversion_format = "3";
    var google_conversion_color = "ffffff";
    var google_conversion_label = "YQ4tCI-jgfy6rytfug";
    //-->
    </script>
    
    Code (markup):
     
    mike33pt, Apr 4, 2009 IP
  5. mike33pt

    mike33pt Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    solved thanks for your help EOM
     
    mike33pt, Apr 6, 2009 IP
  6. mahendras

    mahendras Peon

    Messages:
    597
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Great. Add me reputation if my help worked for you :)
     
    mahendras, Apr 6, 2009 IP