sjgrodriguez
Posts: 26
|
Posted: 02/11/2012, 12:10 AM |
|
Hi there. I have an editable grid with three textboxes called VALOR_PPM, DILUCION and RESULTADO
With Javascript, i want to calculate the value of the RESULTADO textbox based on the formulae: PPM * DILUCION .
My javascript code is:
<script language="javascript">
function fadd()
{
var uno,dos,resultado_final;
uno=parseFloat(document.Tasks.VALOR_PPM.value.replace(/,/gi, '.'));
//Take the value of second textbox and convert it to float
dos=parseFloat(document.Tasks.DILUCION.value.replace(/,/gi, '.'));
resultado_final=(uno*dos);
resultado_final = resultado_final.toString()
var myNewString = resultado_final.replace(".", ",");
//show the result in the result textbox
document.Tasks.RESULTADO.value=myNewString;
}
</script>
Also i have set the Onchange Event "fadd(this)" for the textboxes VALOR_PPM and DILUCION.
It works great when the editable grid has only one row. However, if it has two or more rows, it doesnt work. Actually, it does nothing.
How can i do to make this code work with multiple rows in an editable grid?
I have tried many things, with no success.
I hope that someone can help me.
Thanks in advance,
Sergio Gómez
|
|
|
TheunisP
Posts: 342
|
Posted: 02/11/2012, 12:56 AM |
|
you cant access it like that - each rows elements' have a qualifier e.g. a row number appended - have a look at the source of the page when there is data in the grid you will notice that you have controls like this:
textbox_1
textbox_2
textbox_3
...
textbox_4
so you will need to take that in account as you have it - there really no document.Tasks.VALOR_PPM.value but there will be a document.Tasks.VALOR_PPM_1.value
|
|
|
TheunisP
Posts: 342
|
Posted: 02/11/2012, 1:01 AM |
|
a shot in the dark but this should solve your problem, instead of
document.Tasks.VALOR_PPM.value
use
document.Tasks.VALOR_PPM_{Tasks:rowNumber}.value
in actual fact you should see CCS using the {Tasks:rowNumber} attribute to give the elements their ids and names
|
|
|
sjgrodriguez
Posts: 26
|
Posted: 02/11/2012, 3:16 AM |
|
Hi Theunis and thanks a lot for your answer. It´s not the first time you help me.
Ok, i have done with you propose, and now it´s getting better but still doesn´t work. Let me explain.
All the id´s and names are set correctly, and when i take a look to the code, it´s showing for each row, different names and id´s with _1 , _2, etc.
However, the javascript code doesn´t look to accept the part:
document.Tasks.VALOR_PPM_{Tasks:rowNumber}.value
If i set instead of it, the next code:
document.Tasks.VALOR_PPM_1.value , it does the calculation ok for the first row. If i set the code document.Tasks.VALOR_PPM_2.value, it does the calculation for the second row.. However, when i set:
document.Tasks.VALOR_PPM_{Tasks:rowNumber}.value
it does nothing and when i take a look at the code after the page is published, what i see is:
document.Tasks.VALOR_PPM_.value
Its like if its not accepting the {Tasks:rownumber} code.
Do you know why?
Thanks in advance
Regards
Sergio Gómez
|
|
|
datadoit
|
Posted: 02/11/2012, 5:37 AM |
|
Take a look at this for info on accessing editable grid row values via
javascript: http://forums.codecharge.com/posts.php?post_id=60507
|
|
|
sjgrodriguez
Posts: 26
|
Posted: 02/11/2012, 9:07 AM |
|
Thank you datadoit. I have taken a look to the post. So, in my example, how should i call every row control with javascript?
This is my approach, but it doesnt work:
<script language="javascript">
function fadd()
{
var uno,dos,resultado_final;
uno=parseFloat(TasksElements[j][TasksVALOR_PPMID].value.replace(/,/gi, '.'));
//Take the value of second textbox and convert it to float
dos=parseFloat(TasksElements[j][TasksDILUCIONID].value.replace(/,/gi, '.'));
resultado_final=(uno*dos);
resultado_final = resultado_final.toString()
var myNewString = resultado_final.replace(".", ",");
//show the result in the result textbox
TasksElements[j][TasksRESULTADOID].value=myNewString;
}
</script>
Thanks for your support.
Sergio Gómez
|
|
|
|