onclick event

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • juicy

    onclick event

    Hi,

    I have 4 check box and a textarea. When user check each check box, it will
    append text in the textarea. In onclick event, it calls getSurcharge
    function and append value in variable output. My problem is I failed to
    get value in php variable inside the function.
    Please give some idea on the reason of the problem. Thanks.

    <script language="JavaS cript">
    function getSurcharge(id )
    {
    var output;
    if (document.getEl ementById("chks ur1").checked)
    {output = output + "<? echo $strSurcharge1; ?>"; }

    if (document.getEl ementById("chks ur2").checked)
    {output = output + "<? echo $strSurcharge2; ?>"; }

    if (document.getEl ementById("chks ur3").checked)
    {output = output + "<? echo $strSurcharge3; ?>"; }

    if (document.getEl ementById("chks ur4").checked){ output = output + "<? echo
    $strSurcharge4; ?>"; }
    document.getEle mentById(id).va lue= output;
    }

    <?php
    $strSurcharge1 = "x1";
    $strSurcharge2 = "x2";
    $strSurcharge3 = "x3";
    $strSurcharge4 = "x4";
    ?>

    <input type=checkbox name="chksur1" onclick="getSur charge('duties' )"
    value="<? echo $strSurcharge1; ?>">
    <input type=checkbox name="chksur2" onclick="getSur charge('duties' )"
    value="<? echo $strSurcharge2; ?>">
    <input type=checkbox name="chksur3" onclick="getSur charge('duties' )"
    value="<? echo $strSurcharge3; ?>">
    <input type=checkbox name="chksur4" onclick="getSur charge('duties' )"
    value="<? echo $strSurcharge4; ?>">

    <textarea name= "f_duties" id = "duties" cols=100 rows=10>


  • Jerry Stuckle

    #2
    Re: onclick event

    juicy wrote:[color=blue]
    > Hi,
    >
    > I have 4 check box and a textarea. When user check each check box, it will
    > append text in the textarea. In onclick event, it calls getSurcharge
    > function and append value in variable output. My problem is I failed to
    > get value in php variable inside the function.
    > Please give some idea on the reason of the problem. Thanks.
    >
    > <script language="JavaS cript">
    > function getSurcharge(id )
    > {
    > var output;
    > if (document.getEl ementById("chks ur1").checked)
    > {output = output + "<? echo $strSurcharge1; ?>"; }
    >
    > if (document.getEl ementById("chks ur2").checked)
    > {output = output + "<? echo $strSurcharge2; ?>"; }
    >
    > if (document.getEl ementById("chks ur3").checked)
    > {output = output + "<? echo $strSurcharge3; ?>"; }
    >
    > if (document.getEl ementById("chks ur4").checked){ output = output + "<? echo
    > $strSurcharge4; ?>"; }
    > document.getEle mentById(id).va lue= output;
    > }
    >
    > <?php
    > $strSurcharge1 = "x1";
    > $strSurcharge2 = "x2";
    > $strSurcharge3 = "x3";
    > $strSurcharge4 = "x4";
    > ?>
    >
    > <input type=checkbox name="chksur1" onclick="getSur charge('duties' )"
    > value="<? echo $strSurcharge1; ?>">
    > <input type=checkbox name="chksur2" onclick="getSur charge('duties' )"
    > value="<? echo $strSurcharge2; ?>">
    > <input type=checkbox name="chksur3" onclick="getSur charge('duties' )"
    > value="<? echo $strSurcharge3; ?>">
    > <input type=checkbox name="chksur4" onclick="getSur charge('duties' )"
    > value="<? echo $strSurcharge4; ?>">
    >
    > <textarea name= "f_duties" id = "duties" cols=100 rows=10>
    >
    >[/color]

    Your problem is the PHP code is executed on the server before the page is sent
    to the client browser. Once the page has been delivered, the javascript runs.
    But PHP has already done it's job and terminated.


    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • juicy

      #3
      Re: onclick event

      I move the php code above the getSurcharge function and try with it, it
      works, but when I change $strSurcharge1 to a paragraph of text instead of
      x1, it couldn't work.

      Please give some idea on the case.
      Thanks.

      Comment

      • juicy

        #4
        Re: onclick event

        I move the php code above the getSurcharge function and try with it, it
        works, but when I change $strSurcharge1 to a paragraph of text instead of
        x1, it couldn't work.

        Please give some idea on the case.
        Thanks.

        Comment

        Working...