Quick questions regarding JS code in ECHO output

Discussion in 'PHP' started by Geekim, Jan 26, 2012.

  1. #1
    I'm trying to define a Google Analytic even tracker on one of my Buttons so i need to add onSubmit="_gaq.push(['_trackEvent', 'Button', 'Click', 'Compare']);"

    the original line is echo '<input id="in_submit" type="submit" name="submit" value="Compare &gt;&gt;" />';
    but if i'll put it like this echo '<input onSubmit="_gaq.push(['_trackEvent', 'Button', 'Click', 'Compare']);" id="in_submit" type="submit" name="submit" value="Compare &gt;&gt;" />';
    it will give me an error..

    any idea what's breaking this line ?
     
    Solved! View solution.
    Geekim, Jan 26, 2012 IP
  2. #2
    you have to escape the ' inside the echo statement

    
    echo '<input onSubmit="_gaq.push([\'_trackEvent\', \'Button\', \'Click\', \'Compare\']);" id="in_submit" type="submit" name="submit" value="Compare &gt;&gt;" />';
    
    PHP:
     
    stephan2307, Jan 26, 2012 IP
  3. Geekim

    Geekim Active Member

    Messages:
    278
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    70
    #3
    @Stephan Thanks a million !
     
    Geekim, Jan 26, 2012 IP