On 8 maio, 12:02, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
Norman escribió:
I am trying to find a way to implement something like:
<FORM name='form1'><TABLE>
server scripting loop (php), generates X (a variable number) lines
with the 3 fields {
<TR><TD><input type='text' name='kminicial[]'></TD>
<TD><input type='text' name='kmfinal[]'
onBlur='document.form1.kmrodados[currentindex].value=document.form1.kmfinal[currentindex].value-
document.form1.kminicial[currentindex].value'></TD>
<TD><input type='text' name='kmrodados[]'></TD></TR>
}
</TABLE></FORM>
Just a simple onBlur math with the first two fields of each line,
putting the result on the third. The problem is the "currentindex"
value, I wasnt able to find how to get this value anywhere, is it
possible to implement this way?
If you use PHP, why don't you do an extra step?
<?php
$rowid = 0;
?>
...
<input type=" name="kmfinal[]"
onblur="updateResultByRowId(<? echo $rowid++; ?>)">
Otherwise, I can only think of this:
<input type=" name="kmfinal[]"
onblur="updateResultByRightField(this)">
function updateResultByRightField(rightField){
var currentForm = rightField.form;
/*
* And then write code to find:
* var leftField = ......
* var resultField
*
* ... either going up from rightField or going
* down from currentForm...
*/
}
One more idea is to asign events to the row but I still prefer option 1 :)
--
--http://alvaro.es- Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:http://bits.demogracia.com
-- Mi web de humor al baño María:http://www.demogracia.com
--
Thanks Alvaro, I tried your 1st approach:
<SCRIPT LANGUAGE=\"JavaScript\">
function calcula(indice) {
document.formulario.kmrodados[indice].value =
document.formulario.kmfinal[indice]-
document.formulario.kminicial[indice];
return true;
}
</SCRIPT>
and later, initialize the $indiceatual=0 on php, and inside the loop:
<TD><input type='text' name='kminicial[]'>
<TD><input type='text' name='kmfinal[]' onBlur='calcula(" .
$indiceatual++ . ");'>
<TD><input type='text' name='kmrodados[]'>
but this generates an javascript error stating:
this.document.formulario.kmrodados has no properties
on the 1st line of the calcula() function. The form name is declared
as 'formulario'. Can you see what Im doing wrong here?
Thank in advance,
Norman