Alert at end of function wont show up becaus of 2 lines help plz

Hi

Im bulding a form and during the validation i found out that two line of code are causing problem.

If i remove them everything is fine.Unfortunately i need them to hide the spans with the .invalide class.

I want the spans to be visible only if there is an error.

Here is my webpage : http://kmultim.com/index.php?idSection=contact

‘Clicking on Envoyer start the fonction’

If i remove thes two line the alert will pop-up
.

		
erreurSpan[i].innerHTML ='';
erreurSpan[i].style.display ='none';

function validForm(oForm)
{
	var erreur = 0; 
	var erreurSpan = document.getElementsByClassName('invalide')// liste des span avec la classe error
	//var regExpCourriel = /^([\\w-]+(?:\\.[\\w-]+)*)@((?:[\\w-]+\\.)*\\w[\\w-]{0,66})\\.([a-z]{2,6}(?:\\.[a-z]{2})?)$/i	;
	for(var i = 0; i < oForm.elements.length ; i++)
	{		
		
		erreurSpan[i].innerHTML ='';// buggy line 1
		erreurSpan[i].style.display ='none'; // buggy line 2
		var laValeurInp = oForm.elements[i].value

		if(oForm.elements[i].className == "inputForm") // get the element of the form with the class inputForm
		{	
			
			if(laValeurInp == "")  // input or text is empte
			{
				erreurSpan[i].innerHTML ="Ce champ ne doit pas &ecirc;tre vide";
				erreurSpan[i].style.display ="block";
				erreur = 1;				
			}else
				{
					
					if(laValeurInp.length < 2) //input or text is less than 2 characters
					{
						erreurSpan[i].innerHTML ="Ce doit contenir au moin deux charact&egrave;res";
						erreurSpan[i].style.display ="block";
						erreur = 1;	
					}
				}

		}
		
	}
	alert(1);
}

The reason the 2 lines are causing an error is because your counting the length of all the elements in the form instead of just the span elements, if you change the argument to…

for (var i = 0; i < erreurSpan.length; i++)

then your code should work fine after that.

Yes but if the condition if(oForm.elements[i].className == “inputForm”) would filter those unneeded element . your sugestion remove the need for it :).

I just remembered that found getElementsByClassName () doesn’t exist in internet explorer.
var erreurSpan = document.getElementsByClassName(‘invalide’); // this dosent work

i used var erreurSpan = $(‘.invalide’); with jquery since im already using jquery for something else in the page.

Now everything is worcking fine thanks :).