Don_S
Posts: 50
|
| Posted: 12/06/2005, 6:31 AM |
|
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.
Can this be done in asp on the client side or do I have to have Javascript to get this to work?
Anyhelp would be great,
Don
|
 |
 |
Walter Kempees
|
| Posted: 12/06/2005, 8:35 AM |
|
Don
Am not into ASP but would you consider doing calculation in Java, because
then you could cath the onchange or onkeyup of your list calculate in JAVA
en put result on the screen instantly.
Am also not a fluent JAVA man, but to calculate in java must be googable.
Walter
"Don_S" <Don_S@forum.codecharge> schreef in bericht
news:64395a0c9993cd@news.codecharge.com...
> 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.
>
> Can this be done in asp on the client side or do I have to have Javascript
> to
> get this to work?
>
> Anyhelp would be great,
> Don
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
Don_S
Posts: 50
|
| Posted: 12/06/2005, 9:13 AM |
|
Yes, I would be willing do to it in Java, as a matter of fact I posted to the Java forum as well, but have not gotten a response yet. I did try googling for the Java code and was able to find some info, but as I am not a Java person either I could not convert it to my problem.
Don
|
 |
 |
Walter Kempees
|
| Posted: 12/06/2005, 10:42 AM |
|
Give me time and i'll give it a try4U
If anybode beats me to it, great !
Walt
"Don_S" <Don_S@forum.codecharge> schreef in bericht
news:64395c6d76115c@news.codecharge.com...
> Yes, I would be willing do to it in Java, as a matter of fact I posted to
> the
> Java forum as well, but have not gotten a response yet. I did try googling
> for
> the Java code and was able to find some info, but as I am not a Java
> person
> either I could not convert it to my problem.
>
> Don
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
Don_S
Posts: 50
|
| Posted: 12/06/2005, 10:51 AM |
|
That would be great Walt, thank you very much!
Don
|
 |
 |
Walter Kempees
|
| Posted: 12/06/2005, 1:08 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.
"Don_S" <Don_S@forum.codecharge> schreef in bericht
news:64395ddc8aa571@news.codecharge.com...
> That would be great Walt, thank you very much!
>
> Don
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
Walter Kempees
|
| Posted: 12/06/2005, 1:18 PM |
|
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
"Walter Kempees" <kempe819@planet.nl> schreef in bericht
news:dn4ujh$4s2$1@news.codecharge.com...
> 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.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> "Don_S" <Don_S@forum.codecharge> schreef in bericht
>news:64395ddc8aa571@news.codecharge.com...
>> That would be great Walt, thank you very much!
>>
>> Don
>> ---------------------------------------
>> Sent from YesSoftware forum
>> http://forums.codecharge.com/
>>
>
>
|
|
|
 |
Don_S
Posts: 50
|
| Posted: 12/06/2005, 1:48 PM |
|
It is absolutely what I wanted! Got it working on my page and now all I have to do is change a little bit of the formatting on my other pages and I will be up and running.
Thank you for all your time put into this.
Don
|
 |
 |
Walter Kempees
|
| Posted: 12/06/2005, 1:50 PM |
|
With pleasure!
"Don_S" <Don_S@forum.codecharge> schreef in bericht
news:6439607317e61b@news.codecharge.com...
> It is absolutely what I wanted! Got it working on my page and now all I
> have to
> do is change a little bit of the formatting on my other pages and I will
> be up
> and running.
> Thank you for all your time put into this.
> Don
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
Don_S
Posts: 50
|
| Posted: 12/06/2005, 3:36 PM |
|
One last question. Any idea on how to query the listbox to get an other field? My listbox is bound to the interger value to do the math, but I need the Text to be written to the DB. I know I should be able to write to a hidden label but can't figure out how to do that.
Don
|
 |
 |
Walter Kempees
|
| Posted: 12/06/2005, 4:06 PM |
|
Not sure I get the question, but
as you already know the Nbr part (integer value) of the selected item from
the listbox (the bound column)
I think you should be able to use that to do an additional lookup
CCDLookup("Description","LookupTablename","Nbr=" & YOURFIELD , ccsInteger),
DBConn)
This is not correct syntax as I'm a PhP'er.
But basically this is it, I think.
Walter
"Don_S" <Don_S@forum.codecharge> schreef in bericht
news:64396206b219e0@news.codecharge.com...
> One last question. Any idea on how to query the listbox to get an other
> field?
> My listbox is bound to the interger value to do the math, but I need the
> Text
> to be written to the DB. I know I should be able to write to a hidden
> label but
> can't figure out how to do that.
>
> Don
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
Walter Kempees
|
| Posted: 12/06/2005, 4:07 PM |
|
BTW using my (PM) can I have a look at the finished product (or part of)
"Don_S" <Don_S@forum.codecharge> schreef in bericht
news:64396206b219e0@news.codecharge.com...
> One last question. Any idea on how to query the listbox to get an other
> field?
> My listbox is bound to the interger value to do the math, but I need the
> Text
> to be written to the DB. I know I should be able to write to a hidden
> label but
> can't figure out how to do that.
>
> Don
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
Don_S
Posts: 50
|
| Posted: 12/07/2005, 10:44 AM |
|
Walter,
PM me and I will give you a link to the project!
Don
|
 |
 |
Benjamin Krajmalnik
|
| Posted: 12/08/2005, 5:34 PM |
|
http://www.w3schools.com/htmldom/dom_obj_option.asp
The code to retrieve the value was:
document.getElementById("ListBox1").value;
I beleieve you can retrieve the textual description by:
document.getElementById("ListBox1").text;
I assume you wanted to get the text that is displayed in the list, and not
the bound item.
Now, if you need to do queries, I do it all over the place where I capture
an event (such as onchange), retrieve a value, and using a popup window
which remains as small as possible, I call another script which retrieves a
value and posts it back to a function in the calling page.
"Don_S" <Don_S@forum.codecharge> wrote in message
news:64396206b219e0@news.codecharge.com...
> One last question. Any idea on how to query the listbox to get an other
field?
> My listbox is bound to the interger value to do the math, but I need the
Text
> to be written to the DB. I know I should be able to write to a hidden
label but
> can't figure out how to do that.
>
> Don
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
|