473,404 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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="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){outpu t = 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>
May 20 '06 #1
3 3025
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){outpu t = 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.
js*******@attglobal.net
==================
May 20 '06 #2
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.

May 20 '06 #3
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.

May 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Andreas Knollmann | last post by:
Hi, I create an object like this: var cell = document.createElement("td"). It doesn't have to be cell. I want this cell to use the onclick event. What doesn't work in the IE as well as with...
2
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } ...
17
by: abs | last post by:
My element: <span onclick="alert('test')" id="mySpan">test</span> Let's say that I don't know what is in this span's onclick event. Is it possible to add another action to this element's onclick...
6
by: Cockroach | last post by:
Hello, I have a problem where the onClick of a table row will activates a window.location event, and inside a cell in that row, an image onClick event shows/hides a div. The problem is that...
4
by: RobG | last post by:
I have a function whose parameter is a reference the element that called it: function someFunction(el) { ... } The function is assigned to the onclick event of some elements in the HTML...
5
by: moondaddy | last post by:
I have a <a> element in a datagrid which wraps some asp.net labels. this element also has an onclick event which does not fire in netscape 6 (and perhaps other browsers for all I know...). Below...
5
by: kai | last post by:
Hi, In ASP.NET , what is the difference between OnClick and Click events for a button? Because we have button click event, it can trigger events, why we still need OnClick? Please help. ...
7
by: extremerep | last post by:
My task is to change the value of a button and then make it functional with the onClick handler. Changing the value to "Play Again" works, but making the onClick work accordingly does not. The...
4
by: sameergn | last post by:
Hi, I have an image in my HTML form which has onclick() handler. There is also a submit button and a text box. Whenever text box has focus and user presses enter, the onclick() event of...
5
by: Stuart Shay | last post by:
Hello All I am working on ASP.NET 1.1 Custom Pager that allows a User to Enter a Number in a TextBox and go to the page selected. Since the OnClick Event does not work in ASP.NET 1.1 for a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.