Probleme script de controle de saisie

Signaler
Messages postés
42
Date d'inscription
samedi 27 mars 2004
Statut
Membre
Dernière intervention
23 juillet 2004
-
Messages postés
389
Date d'inscription
mercredi 23 avril 2003
Statut
Membre
Dernière intervention
17 décembre 2004
-
bonjour,
je suis en train de réaliser le controle de saisie sur mon formulaire.
je souhaite tester deux choses :
*que l'email soit valide (ça ça marche)
*que les champs obligatoires soient bien renseignés (ça ça marche pas)
tant que tout n'est pas correcte je verrouille le bouton de validation
pour cela, j'ai plusieurs fonctions :
//vérification du mail (très efficace)
function verifMail(event,Button) {
var domaines = new Array("ac","ad","ae","af","ag","ai","al","am","an","ao","aq","ar","as","au","aw","az","ba","bb","bd","be","bf","bg","bh","bi","bj","bm","bn","bo","br","bs","bt","bv","bw","by","bz","ca","cc","cd","cf","cg","ch","ci","ck","cl","cm","cn","co","cr","cu","cv","cx","cy","cz","de","dj","dk","dm","do","dz","ec","ee","eg","eh","er","es","et","fi","fj","fk","fm","fo","fr","ga","gd","ge","gf","gg","gh","gi","gl","gm","gn","gp","gq","gr","gs","gt","gu","gw","gy","hk","hm","hn","hr","ht","hu","id","ie","il","im","in","io","iq","ir","is","it","je","jm","jo","jp","ke","kg","kh","ki","km","kn","kp","kr","kw","ky","kz","la","lb","lc","li","lk","lr","ls","lt","lu","lv","ly","ma","mc","md","mg","mh","mk","ml","mm","mn","mo","mp","mq","mr","ms","mt","mu","mv","mw","mx","my","mz","na","nc","ne","nf","ng","ni","nl","no","np","nr","nu","nz","om","pa","pe","pf","pg","ph","pk","pl","pm","pn","pr","pt","pw","py","qa","re","ro","ru","rw","sa","sb","sc","sd","se","sg","sh","si","sj","sk","sl","sm","sn","so","sr","st","sv","sy","sz","tc","td","tf","tg","th","tj","tk","tm","tn","to","tp","tr","tt","tv","tw","tz","ua","ug","uk","gb","um","us","uy","uz","va","vc","ve","vg","vi","vn","vu","wf","ws","ye","yt","yu","za","zm","zr","zw","com","net","org","edu","int","arp","at","gov","mil","su","rev","biz");
var valid = 0;
if (document.all) {
var obj = event.srcElement;
}
if (!document.all && document.getElementById) {
var obj = event.target;
}
var chaine = obj.value;
var exp=/^[a-z][a-z0-9\._-]+@[a-z0-9\._-]+\.([a-z]{2,3})$/i;
if(exp.test(chaine)==true) {
var endOfMail = chaine.split(".");
var getDot = endOfMail[(endOfMail.length)-1];
for (var i=0; i<domaines.length; i++) {
if(getDot == domaines[i]) {
valid = 1;
}
}
} else {
valid = 0;
}
return valid;
}

//vérification des champs obligatoires
function verifOblige(formulaire)
{
if(formulaire.txtSocLib.value=="")
{
return false;
}
else
{
return true;
}
}


pour lancer cesdeux fonctions, j'ai le script suivant :

//vérification du formulaire societe avec vérif des champs obligatoires et de l'email
function verifFormSoc(event,Button,formulaire)
{
if ((verifOblige(formulaire)) && (verifMail(event,Button)))
{
document.getElementById(Button).disabled = false;
}
else
{
document.getElementById(Button).disabled = true;
}
}


et pour vérouiller le bouton :
//action sur l'état d'un bouton
function checkStatusButton(buttonSubmit) {
if(document.getElementById(buttonSubmit).disabled) {
return false ;
} else {
return true ;
}
}


mon formulaire est une jsp dont voici les grandes lignes :
<html>

<form name="formsociete" onsubmit="return checkStatusButton('valider')">
"> *
"> *

</form>

</html>


la vérification du mail fonctionne très bien, mais j'ai l'impression que la fonction de champ obligatoire ne parvient pas à accéder à mon élément txtSocLib.

Est ce que quelq'un pourrait m'aider?
merci beaucoup

5 réponses

Messages postés
389
Date d'inscription
mercredi 23 avril 2003
Statut
Membre
Dernière intervention
17 décembre 2004
1
function verifOblige()
{
if(document.formsociete.txtSocLib.value=="")
{
return false;
}
else
{
return true;
}
}

www.morgan06.fr.fm
Messages postés
42
Date d'inscription
samedi 27 mars 2004
Statut
Membre
Dernière intervention
23 juillet 2004

j'ai déja essayé mais ça ne marche pas. l'email est parfaitement controlé, mais lorsque je rempli le champ, le bouton est toujours bloké..??
une autre idée?
merci qd meme
Messages postés
389
Date d'inscription
mercredi 23 avril 2003
Statut
Membre
Dernière intervention
17 décembre 2004
1
essaye de faire une trace par exemple :

function verifOblige()
{
if(document.formsociete.txtSocLib.value=="")
{
return false;
}
else
{
document.write('coucou');
return true;
}
}

tu verras alors si c ta fonction verifoblige qui plante ou bien si c le bouton

www.morgan06.fr.fm
Messages postés
42
Date d'inscription
samedi 27 mars 2004
Statut
Membre
Dernière intervention
23 juillet 2004

en fait, jai trouvé d'où ça vient. mon champ est bien testé mais il faut lavoir rempli avant de saisir lemail. ou retoucher a lemail ensuite...
la solution serait de faire le test sur tous les champs. je trouve ça un peu lourd.... ms faute de mieux je croi ke je v me rabattre sur ça.
merci
Messages postés
389
Date d'inscription
mercredi 23 avril 2003
Statut
Membre
Dernière intervention
17 décembre 2004
1
derien bonne continuation ;)
www.morgan06.fr.fm