calling javascript functions from php

Discussion in 'PHP' started by dred7, Sep 25, 2006.

  1. #1
    hi, i've been trying to call js through php and it's not working, i'm not sure why. i've searched around and i can't figure out what i'm doing wrong. here's my code:

    
    if (mysql_num_rows($result) == 1) {
        echo "aaa<script language=javascript>changeBtn();</script>";
        } else {
        echo "aab<script language=javascript>alert('anything');</script>";
    }
    
    Code (markup):
    the aaa and aab show up but no alerts or anything else. thx
     
    dred7, Sep 25, 2006 IP
  2. fsmedia

    fsmedia Prominent Member

    Messages:
    5,163
    Likes Received:
    262
    Best Answers:
    0
    Trophy Points:
    390
    #2
    You're probably not using quotes properly. Test out the code withOUT the php and get it working first there, then put it in with the PHP and make sure you have proper use of quotes and escaping quotes.
     
    fsmedia, Sep 25, 2006 IP
  3. dred7

    dred7 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    doh! it turns out i was the echo was being sent to a div through innerHTML and that messed it up. i changed it to document.write and now it works, yay!
     
    dred7, Sep 25, 2006 IP