Click to See Complete Forum and Search --> : If statement......Help


joelo
08-27-2003, 03:56 PM
Please could someone help on how to add an if statement or any conditional statement to the below function such that if a (I am using a dynamic form) field is not displayed on the form, the function will skip to the next field available...........till the end function

here is the function

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

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

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

gcrowan
08-27-2003, 06:01 PM
Write in the additional html input fields so I won't assume I know what you need. Can you clarify the description of your problem?

joelo
08-28-2003, 12:42 AM
since I am using a dynamic form (with loop).....I need the function to check if the form fields exist on the form b/4 processing the function....and any field name that is not displayed at time, the function will skip that field name and process next field name displayed on the form.

By using any conditional statement. i.e.

function passDate(str) {
if PRE_idTESTDATE_ (element) exist then

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

else
skip and check the next field if it exist

}
if TUE_idTESTDATE_ (element) exist then

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

else
skip and end if
}
}

and so on with the rest of the functions

joelo
08-28-2003, 07:49 AM
Please Help me....I am in a bind

joelo
08-28-2003, 02:57 PM
Please Help me....I am in a bind

Exuro
08-28-2003, 06:14 PM
I think this will work:

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

When I made that I assumed that device was a form, and the elements you wanted to test were elements of that form. Anyway, hope that helps!

joelo
08-29-2003, 12:58 AM
Tried it....Did not work

gcrowan
08-29-2003, 02:15 PM
I have a coulpe of ideas. Are you willing to let me see the whole page, minus the database connection(wouldn't want to see passwords or sensitive info)?