Don_S
Posts: 50
|
Posted: 12/05/2005, 3:35 PM |
|
Hi Everyone,
Here's what I need to do...
I have 2 listboxes:
Start_Value
End_Value
Both are pulled from a database with "Nbr" as the Bound Column and "Disc" as the Text Column.
I have a textbox named "Total", which needs to be a calculated value based off of the 2 listboxes:
Total= Start_Value - End_Value
I have tried numerous sets of code on the onChange event for the End_Value listbox but have not gotten anything to work.
If anyone can help me with this code that would be great. I have little experience with Java and this is driving me nuts!
Thanks in advance,
Don
|
|
|
Walter Kempees
|
Posted: 12/06/2005, 1:23 PM |
|
Are you ready for it?
Here it comes, first have a look at my (doing nothing) example page.
http://213.10.55.10/aangeenbrug/Don_S.php
is that what you meant by your request.
Listbox1 and 2 are database tables (id, description) containg corresponding
values like (1,"Value 1") and so on.
CCS Designmode of Page:
Listbox1: Properties->Format->id has a value of ListBox1
Listbox2: Properties->Format->id has a value of ListBox2
TextBox: Properties->Format->id has a value of ResultBox
ListBox2: Properties->Events->On Change has CustomCode
// -------------------------
Write your own code here.
// -------------------------
SumNumbers();
//End Custom Code
In your page Design switch to HTML and add the following code just BEFORE
<script language="JavaScript" type="text/javascript">
//End Include JSFunctions
<script language="JavaScript">
<-- To hide from old browsers
function SumNumbers()
{
var x=0;
var y=0;
var z=0;
x = document.getElementById("ListBox1").value;
y = document.getElementById("ListBox2").value;
var z = (1*x) + (1*y);
document.getElementById("ResultBox").value = z;
}
//Stop Hiding -->
Well, that should do the trick Don, asssuming you are not using frames,
iframes and the likes.
It sort of depends on running in the same page (document.)
Let me know if it works.
As an add on:
Add the same Custom event to ListBox1, this will cater for those Murphies
that choose from listbox1 listbox2 and then go and change listbox1.
An explanation for the var z = (1*x) + (1*y);
JavaScript has auto typing so assigning a value of 1 to variable x should be
a integer value 1, the same going for y.
But while building this it kept giving a result of 53 when listbox1= 5 and
listbox2= 3, so for some reason x or y where interpreted as string values
resulting in the "+" operation functioning as a concatenate.
Being a workarounder I thought to multiply them both by 1 typing x and y
back to integers.
That worked.
Any helpfull comment from an experienced JS'er will be appreciated.
Walter
|
|
|
matheus
Posts: 386
|
Posted: 12/07/2005, 2:32 AM |
|
Could use Number(x) + Number(y) too.
_________________
Matheus Trevizan
Dynamix Software Ltda.
Blumenau SC Brasil
www.dynamix.com.br |
|
|
Walter Kempees
|
Posted: 12/07/2005, 2:39 AM |
|
Thanks, was waiting for a usefull comment.
I googled my fingertops numb on this, so for now I use (1*x)+(1*y)
Thank Matheus.
"matheus" <matheus@forum.codecharge> schreef in bericht
news:94396ba53219bc@news.codecharge.com...
> Could use Number(x) + Number(y) too.
> _________________
> Matheus Trevizan
>
> Dynamix Software Ltda.
> Blumenau SC Brasil
> www.dynamix.com.br
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
Walter Kempees
|
Posted: 12/07/2005, 2:41 AM |
|
Matheus said in codecharge.java:
Quote :
"Walter Kempees" <kempe819@planet.nl> schreef in bericht
news:dn6e4b$rk9$1@news.codecharge.com...
> Thanks, was waiting for a usefull comment.
> I googled my fingertops numb on this, so for now I use (1*x)+(1*y)
> Thank Matheus.
>
> "matheus" <matheus@forum.codecharge> schreef in bericht
>news:94396ba53219bc@news.codecharge.com...
>> Could use Number(x) + Number(y) too.
>> _________________
>> Matheus Trevizan
>>
>> Dynamix Software Ltda.
>> Blumenau SC Brasil
>> www.dynamix.com.br
>> ---------------------------------------
>> Sent from YesSoftware forum
>> http://forums.codecharge.com/
>>
>
>
|
|
|
|