Click to See Complete Forum and Search --> : pass value


joelo
08-27-2003, 02:01 AM
Please could someone help me out...I don't know what I am doing wrong. I 've a dynamic form... when there is one record on the form...function does not work...but function works when there is more than one record on the form.

Please help me out


function passDate(str) {
for(i=0; i<document.device.PRE_idTESTDATE_.length; i++){
document.device.PRE_idTESTDATE_[i].value = str;
document.device.TUE_idTESTDATE_[i].value = str;
}
}

function passTechnicianname(str1) {
for(i=0; i<document.device.PRE_idTECHNICIANNAME_.length; i++){
document.device.PRE_idTECHNICIANNAME_[i].value = str1;
}
for(i=0; i<document.device.TUE_idTECHNICIANNAME_.length; i++){
document.device.TUE_idTECHNICIANNAME_[i].value = str1;
}
for(i=0; i<document.device.SUN_idTECHNICIANNAME_.length; i++){
document.device.SUN_idTECHNICIANNAME_[i].value = str1;
}
for(i=0; i<document.device.MON_idTECHNICIANNAME_.length; i++){
document.device.MON_idTECHNICIANNAME_[i].value = str1;
}
}

function passMonthyear(str2) {
for(i=0; i<document.device.PRE_idMONTHYEAR_.length; i++){
document.device.PRE_idMONTHYEAR_[i].value = str2;
}
for(i=0; i<document.device.TUE_idTECHNICIANNAME_.length; i++){
document.device.TUE_idMONTHYEAR_[i].value = str2;
}
for(i=0; i<document.device.SUN_idTECHNICIANNAME_.length; i++){
document.device.SUN_idMONTHYEAR_[i].value = str2;
}
for(i=0; i<document.device.MON_idTECHNICIANNAME_.length; i++){
document.device.MON_idMONTHYEAR_[i].value = str2;
}
}

Gollum
08-27-2003, 02:35 AM
It's probably due to a feature of Javascript in browsers where when a number of form input elements have the same name, they will be grouped together in an array under that name, but when there is only one, the name will refer to the element itself.
I assume that the document.device is set up as an object referencing for element names, if so you could modify your code as follows...

if ( document.device.idTESTDATE_ instanceof Array )
{
for(i=0; i<document.device.PRE_idTESTDATE_.length; i++)
{
document.device.PRE_idTESTDATE_[i].value = str;
document.device.TUE_idTESTDATE_[i].value = str;
}
}
else
{
document.device.PRE_idTESTDATE_.value = str;
document.device.TUE_idTESTDATE_.value = str;
}

joelo
08-27-2003, 03:17 AM
now it works when there is on record on the form and will not work when there more than one record.... Please I need it to work both ways


thanks

Khalid Ali
08-27-2003, 08:13 AM
you need to res visit your coding logic,it seems to me that there ae problems in the over all coding structure.

Post a link to the full page so that we can see what are you doing

joelo
08-27-2003, 09:13 AM
here it is

Khalid Ali
08-27-2003, 09:33 AM
seems like u have a tonne of asp code in it,post a live link....that one can visit rather then forcing some one to run the IIS on their machine.