Le code suivant bugue sous internet explorer, mais pas sous firefox.
function test_champ(champ) {
// le with ci-dessous permet d'abréger
"document.forms.form1.p1.value" en "p1.value"
with (document.forms.form1) {
yo = compter(posMC) * posOR.value * 3 + compter(leadMC) *
leadOR.value * 10 + compter(notoURL) * notoOR.value * 10 ;
prix = (yo - 500) * 0.0095;
if (prix < 0) { prix = "gratis !!!"; }
total.value = yo;
tarif.value = prix;
}
}
function compter(theField)
{
var strLineCounter = 1;
for (var i = 0; i < theField.value.length; i++)
{
var strChar = theField.value.substring(i, i + 1);
if (strChar == '\n')
{
strLineCounter += 1;
}
}
return strLineCounter;
}
Ces fonction sont appelées dans le champ du formulaire : type
onblur="test_champ(this)"