/    Sign up×
Community /Pin to ProfileBookmark

If statement……Help

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;
}
}

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@gcrowanAug 27.2003 — 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?
Copy linkTweet thisAlerts:
@joeloauthorAug 28.2003 — 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
Copy linkTweet thisAlerts:
@joeloauthorAug 28.2003 — Please Help me....I am in a bind
Copy linkTweet thisAlerts:
@joeloauthorAug 28.2003 — Please Help me....I am in a bind
Copy linkTweet thisAlerts:
@ExuroAug 28.2003 — I think this will work:
[SIZE=2]
function passDate(str) {
[b] if (document.device.PRE_idTESTDATE_) {[/b]
document.device.PRE_idTESTDATE_.value = str;
for(i=0; i&lt;document.device.PRE_idTESTDATE_.length; i++){
document.device.PRE_idTESTDATE_[i].value = str;
}
[b] }
if (document.device.TUE_idTESTDATE_) {[/b]
document.device.TUE_idTESTDATE_.value = str;
for(i=0; i&lt;document.device.TUE_idTESTDATE_.length; i++){
document.device.TUE_idTESTDATE_[i].value = str;
}
[b] } [/b]
}
[/SIZE]

When I made that I assumed that [FONT=courier new]device[/FONT] was a form, and the elements you wanted to test were elements of that form. Anyway, hope that helps!
Copy linkTweet thisAlerts:
@joeloauthorAug 29.2003 — Tried it....Did not work
Copy linkTweet thisAlerts:
@gcrowanAug 29.2003 — 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)?
×

Success!

Help @joelo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...