I have array which length is 13 .
form has 13 simultaneous fields user can enter in any field i want that if user enter 5 or 7 or any field value then i want add validation that it's previous field value should not be empty and it should not check validation for next field.
I have used this code ...
datesId[0] = "bankNocForTorDateId";
datesId[1] = "advertisingDateShortlistingId";
datesId[2] = "torShortlistFinalizedDateId";
datesId[3] = "bankNocForShortlistDateId";
datesId[4] = "rfpDraftToBankDateId";
datesId[5] = "bankNocForRfpDateId";
datesId[6] = "rfpIssuedDateId";
datesId[7] = "proposalReciptDateTechnicalId";
datesId[8] = "evaluationFinalTechnicalDateId";
datesId[9] = "bankNocTechnicalDateId";
datesId[10] = "proposalReciptDateFinancialId";
datesId[11] = "evaluationFinalCombinedDateId";
datesId[12] = "nocBankDraftDate";
for(var i = 0; i<datesId.length ; i++ ){
if(!(document.getElementById (datesId[i]).value == "")){
for(var j =datesId[i].length-1 ;j>0 ; j-- ){
if(document.getElementById(datesId[j]).value == ""){
var message = "Please Enter "+datesLabel[j];
alert(message);
return false;
}
}
}
}
Actually i am new in Javascript...not having much idea about it.I have made this logic on the basis of java. please clearify what's basic difference.
Thanks in Advance
-
2I'm curious -- you talk about Javascript, and your code looks like Javascript, but not only do you tag Java, but you tag Spring and Struts, which AFAIK are Java-only frameworks. Why?awksp– awksp2014年07月08日 05:49:41 +00:00Commented Jul 8, 2014 at 5:49
-
Actually i am new so i don't have much idea about this.user3595144– user35951442014年07月08日 05:52:32 +00:00Commented Jul 8, 2014 at 5:52
-
ok but can you tell me what should i do to resolve this problemuser3595144– user35951442014年07月08日 05:55:04 +00:00Commented Jul 8, 2014 at 5:55
-
@user3595144 I'd advise you read the little things that appear when you hover over the tags, and only add tags that are relevant to your problem. Otherwise you get people like me who don't know Javascript reading your question.awksp– awksp2014年07月08日 05:56:47 +00:00Commented Jul 8, 2014 at 5:56
-
thanks bt can you tell how i can iterate this one .user3595144– user35951442014年07月08日 06:00:57 +00:00Commented Jul 8, 2014 at 6:00
1 Answer 1
Done!
var datesId = []
datesId[0] = "bankNocForTorDateId";
datesId[1] = "advertisingDateShortlistingId";
datesId[2] = "torShortlistFinalizedDateId";
datesId[3] = "bankNocForShortlistDateId";
datesId[4] = "rfpDraftToBankDateId";
datesId[5] = "bankNocForRfpDateId";
datesId[6] = "rfpIssuedDateId";
datesId[7] = "proposalReciptDateTechnicalId";
datesId[8] = "evaluationFinalTechnicalDateId";
datesId[9] = "bankNocTechnicalDateId";
datesId[10] = "proposalReciptDateFinancialId";
datesId[11] = "evaluationFinalCombinedDateId";
datesId[12] = "nocBankDraftDate";
// if datesId[6] value is not blank
if (datesId[6] != ''){
// validate previous 5 field values should not be blank, but it should not check next 6 value.
for (var i = (6-5); i < 6; i ++){
console.log('validating field ' + datesId[i] + " (index=" + i + ")")
if (datesId[i] == ''){
alert('Field ' + datesId[i] + " must not be blank!")
}
}
}
answered Jul 8, 2014 at 6:02
Nick Grealy
26.3k9 gold badges112 silver badges127 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
user3595144
Hi you have used fixed case but user can enter any value that means user will enter value from form so next value should not checked of entered value but it must validate previous value .
Nick Grealy
I don't understand. Maybe you can provide an example of what you mean?
user3595144
i mean in my form there are 13 field for date simultanously . user can enter any field value. but i want that if user enter any field value then it's previous value should not be empty but next value it should not checked.
Explore related questions
See similar questions with these tags.
lang-js