Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to Call javascript function from php code?

    Hi,
    I wana call javascript function frm php code in my else block,i tried this way
    <?PHP
    if()
    {
    SOME CODE
    }
    else
    {
    echo "<script language=javascript>divclose()</script>";//divclose() function just

    make this div style to none
    }
    ?>


    bt it didnt work.Help is required how can i call javascript function from php code,and i

    dont wana call this javascript function on any event like onClick() or onMouseOver().I want

    this fuction to be called when else block will run.
    Telling the bigger picture of my problem,my form is appearing in a div and i want to close

    this div(mydiv.style.display = "none") in javascript function,problem i m facing is i m

    unable to call a javascript function.Can any tell me an alternate way of how can i make my

    div-display-style="none" using php code.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,464
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    I made this little test and it works fine.

    Are you sure you have a Javascript function on your page or
    in an external .js file? Maybe there's nothing to call. Since we
    can't see the rest of your script ...

    Here's my test:
    PHP Code:
    <?php

    echo "
    <html>
    <head>
    <SCRIPT LANGUAGE='javascript'>
    function DivClos() {
    alert (\"this is a test\");
    }
    </SCRIPT>
    </head>
    <body>
    "
    ;

    $x=1;

    if(
    $x==0)
    {
    // SOME CODE
    }
    else
    {
    echo 
    "<SCRIPT LANGUAGE='javascript'>DivClos();</SCRIPT>\n";
    }

    echo 
    "
    </body>
    </html>
    "
    ;
    ?>

  • #3
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ya i checked the code in which javascript function is called from PHP code,bt when i used the same statement in my code,it didnt call the javascript function.I have seperate JS file and javascript function there,even i wrote the closediv() function in php file bt still result is the same.......actually i m using AJAX,i have php page one in which div style is set to none and on button click i m calling AJAX function which loads the form in tht closed div and make it style to display...Wat i want is to set display style property of div to none so tht i can call it,and for tht i need to call javascript function without any event trigger.For some reason javascript function is not called in my code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •