Posted by Jerry Stuckle on 05/20/06 06:44
juicy wrote:
> 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="JavaScript">
> function getSurcharge(id)
> {
> var output;
> if (document.getElementById("chksur1").checked)
> {output = output + "<? echo $strSurcharge1; ?>"; }
>
> if (document.getElementById("chksur2").checked)
> {output = output + "<? echo $strSurcharge2; ?>"; }
>
> if (document.getElementById("chksur3").checked)
> {output = output + "<? echo $strSurcharge3; ?>"; }
>
> if (document.getElementById("chksur4").checked){output = output + "<? echo
> $strSurcharge4; ?>"; }
> document.getElementById(id).value= output;
> }
>
> <?php
> $strSurcharge1 = "x1";
> $strSurcharge2 = "x2";
> $strSurcharge3 = "x3";
> $strSurcharge4 = "x4";
> ?>
>
> <input type=checkbox name="chksur1" onclick="getSurcharge('duties')"
> value="<? echo $strSurcharge1; ?>">
> <input type=checkbox name="chksur2" onclick="getSurcharge('duties')"
> value="<? echo $strSurcharge2; ?>">
> <input type=checkbox name="chksur3" onclick="getSurcharge('duties')"
> value="<? echo $strSurcharge3; ?>">
> <input type=checkbox name="chksur4" onclick="getSurcharge('duties')"
> value="<? echo $strSurcharge4; ?>">
>
> <textarea name= "f_duties" id = "duties" cols=100 rows=10>
>
>
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@attglobal.net
==================
[Back to original message]
|