CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> General/Other

 Javascript OnChange event on textbox in Editable Grid

Print topic Send  topic

Author Message
Slopey

Posts: 33
Posted: 01/19/2007, 7:59 AM

Hi All,

I have an editable grid called TimesheetDetail which contains fields (textboxes) for users to enter numbers into which are named TimesheetDetailMon through TimesheetDetailSun respectively. When a user updates one of the textboxes I'd like to calculate the sum of all those boxes on the same grid line/record and put the result in another textbox field named TDT.

How do I reference the appropriate textboxes correctly in javascript? I've tried putting code in the OnChange event of the TimesheetDetailMon box, but I can't get it to work - for example - how to copy the TimesheetDetailMon value to the TDT textbox when the OnChange event fires?

I've tried something like:

document.TimesheetDetail.TDT.value = document.TimesheetDetail.TimesheetDetailMon.value;

But to be honest I don't know how to reference the text boxes correctly within the editable grid.

Any help gratefully received!

Cheers,
S.
View profile  Send private message
matheus

Posts: 386
Posted: 01/19/2007, 9:27 AM

You need know which line in EditableGrid was change.

To do this, in onchange, get this object (textbox).

Parse name textbox, it will be something like this:

NameTextbox_1
NameTextbox_5

get text after '_', this was the line.

_________________
Matheus Trevizan

Dynamix Software Ltda.
Blumenau SC Brasil
www.dynamix.com.br
View profile  Send private message
Slopey

Posts: 33
Posted: 01/19/2007, 2:21 PM

The table is generated from a database query so I can't code up the rows individually, I need to do something like:

document.TimesheetDetail.TextBox_1_(n).value = document.TimesheetDetail.TextBox_5_(n).value

How do I get the reference the row in which the textbox which fired the onchange event is located? Is there a current row property I could use? You say parse the conrol name - how do I get it in the first place?

And is the above syntax for the reference to the textbox object correct i.e.:

document.TimesheetDetail.<controlname> ?

Cheers,
S
View profile  Send private message
marcwolf


Posts: 361
Posted: 01/21/2007, 3:27 AM

Hi Slopey

I have done this and I'll try and include the code below.

This part will loop through the grid and execute a totalling function. The grid has 12 rows

  
function ReCalc() {  
  var result = true;  
  var amt1 =0;  
  var amt =0;  
  var tmp;  
   for (var j = 1; j <12; j++) {  
              // checkf for existance of the element  
              if (eval("document.forms[\"order_item\"].price_total_" + j)) {  
                     tmp = "amt1 = document.forms[\"order_item\"].price_total_" + j;  
                     eval(tmp);  
                     amt = amt + amt1  
              }  
       }  
      return amt  
}  

I have not tested the actual summing part as I had called a function here that did a lot of other processing.

Hope this helps.
Dave
_________________
' Coding Coding Coding
Keep Those Keyboards Coding.
Raw Code!!!!!!!
View profile  Send private message
Slopey

Posts: 33
Posted: 01/22/2007, 6:06 AM

Thanks for that - I'm now able to do:

document.forms["TimesheetDetail"].TDT_1.value = document.forms["TimesheetDetail"].TimesheetDetailMon_1.value;

Where the _1 is the reference to the first row on the grid.

How do I know which control (or which row) has fired the OnChange event?

As Matheus says - I need to parse the control name to get the row number - but how do I do that in javascript? Is there a calling object which I can reference with a name property?
View profile  Send private message
matheus

Posts: 386
Posted: 01/22/2007, 9:17 AM

You'll need do a onchange function in all controls, and then parse.
_________________
Matheus Trevizan

Dynamix Software Ltda.
Blumenau SC Brasil
www.dynamix.com.br
View profile  Send private message
Slopey

Posts: 33
Posted: 01/22/2007, 3:35 PM

Yes - but what do I parse??? How do I get the control name which fired the event? I'm only using one onchange function for the initial row which in the grid which is shown in the designer - so where do I get the name of the control who's onchange event it is?
View profile  Send private message
matheus

Posts: 386
Posted: 01/23/2007, 2:30 AM

onchange="functionA(this);"

Then the name of control you get like this.

function functionA(cmp){
alert(cmp.name);
}
_________________
Matheus Trevizan

Dynamix Software Ltda.
Blumenau SC Brasil
www.dynamix.com.br
View profile  Send private message
Slopey

Posts: 33
Posted: 01/23/2007, 4:43 AM

Perfect! :)

Many thanks all :)
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.