can we have 2 different versions of function depending on certain condition?

Discussion in 'PHP' started by aayybb, Oct 30, 2008.

  1. #1
    In the following simplified code, different version of javascript function A is used depending on something is true or false in the php program?? Is this valid?


    <head>
    <script language="javascript"><!--
    <?php
    if (something true)
    {
    ?>
    function A()
    {
    document.write ("hello");
    }
    <?php
    }
    else
    ?>
    function A()
    {
    document.write("bye");
    }
    <?php
    } ?>
    //--></script>
    </head>

    <body>
    <script language="javascript">
    something = true;
    .... onclick ="function A()"
    </script>
    </body>
     
    aayybb, Oct 30, 2008 IP
  2. penalty

    penalty Member

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #2
    yes, should be valid because only one js function gets printed
     
    penalty, Oct 30, 2008 IP
  3. aayybb

    aayybb Peon

    Messages:
    128
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks a lot for the reply. One more question. Are we treating the php code inside javascript as comment so we should comment it out??
     
    aayybb, Oct 30, 2008 IP