PDA

View Full Version : adding to div's rather than replacing content



fou2enve
May 25th, 2007, 12:04 PM
function validateDateA() {
var lengthCheck = document.form1.DateA1.value
if (lengthCheck.length != 6) { document.getElementById('div1').innerHTML = "<p class='alertred'>Date Arriving is NOT 6 Digits! Please fix! </p>"; showdiv('div1');}
if (lengthCheck.length == 6) { hidediv('div1');}

}

function validateDateD() {
var lengthCheck = document.form1.DateD1.value
if (lengthCheck.length != 6) { document.getElementById('div1').innerHTML = "<p class='alertred'>Date Departing is NOT 6 Digits! Please fix! </p>"; showdiv('div1');}
if (lengthCheck.length == 6) { hidediv('div1');}

}



Hello all. I have a bit of an issue. I have functions that if there value is not true, it updates a div tag with an error message, it works quite well to tell the user that something is not right with their entry, but what happens if they are both error, the function thats activated last shows its error. is there a way i can keep 1 div box and have both error message show if the case arises?

Mr J
May 25th, 2007, 02:09 PM
Try this


function validateDateA(){
isOk=1
var lengthCheck = document.form1.DateA1.value

if(lengthCheck.length != 6){
document.getElementById('div1').innerHTML = "<p class='alertred'>1 Date Arriving is NOT 6 Digits! Please fix! </p>";
isOk=0
}

var lengthCheck2 = document.form1.DateD1.value

if(lengthCheck2.length != 6){
document.getElementById('div1').innerHTML += "<p class='alertred'>2 Date Departing is NOT 6 Digits! Please fix! </p>";
isOk=0
}


if(isOk==0){
showdiv('div1');
}
else{
hidediv('div1');
}

}