FBJS : ou mettre le javascript étant dans <head> en html sans le head en fbjs ?

quinton75 Messages postés 44 Date d'inscription mercredi 13 octobre 2010 Statut Membre Dernière intervention 6 juillet 2011 - 3 févr. 2011 à 14:33
quinton75 Messages postés 44 Date d'inscription mercredi 13 octobre 2010 Statut Membre Dernière intervention 6 juillet 2011 - 8 févr. 2011 à 23:24
<html> 
<head> 
<title>Webform</title> 
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> 
<script language="javascript"> 
var dtCh='/'; 
var minYear=1900; 
var maxYear=2100; 
function isValidInteger(s){ 
var i; 
for(i=0;i<s.length;i++){ 
var c=s.charAt(i); 
if(((c<'0')||(c>'9'))) return false; 
} 
return true; 
} 
function stripCharsInBag(s,bag){ 
var i; 
var returnString=''; 
for(i=0;i<s.length;i++){ 
var c=s.charAt(i); 
if(bag.indexOf(c)==-1) returnString+=c; 
} 
return returnString; 
} 
function daysInFebruary(year){ 
return(((year%4==0)&&((!(year % 100 == 0))||(year%400==0)))?29:28); 
} 
function DaysArray(n){ 
for(var i=1;i<=n;i++){ 
this[i]=31; 
if(i==4||i==6||i==9||i==11){this[i]=30;} 
if(i==2){this[i]=29;} 
} 
return this; 
} 
function isDateOK(dtStr){ 
if(dtStr=='') return true; 
var daysInMonth=DaysArray(12); 
var pos1=dtStr.indexOf(dtCh); 
var pos2=dtStr.indexOf(dtCh,pos1+1); 
var strDay=dtStr.substring(0,pos1); 
var strMonth=dtStr.substring(pos1+1,pos2); 
var strYear=dtStr.substring(pos2+1); 
strYr=strYear; 
if(strDay.charAt(0)=='0'&&strDay.length>1) strDay=strDay.substring(1); 
if(strMonth.charAt(0)=='0'&&strMonth.length>1) strMonth=strMonth.substring(1); 
for(var i=1;i<=3;i++){ 
if(strYr.charAt(0)=='0'&&strYr.length>1) strYr=strYr.substring(1); 
} 
month=parseInt(strMonth); 
day=parseInt(strDay); 
year=parseInt(strYr); 
if(pos1==-1||pos2==-1){ 
alert('Le format de date devrait être : dd/mm/yyyy.'); 
return false; 
} 
if(strMonth.length<1||month<1||month>12){ 
alert('Veuillez entrer un mois valide.'); 
return false; 
} 
if(strDay.length<1||day<1||day>31||(month==2&&day>daysInFebruary(year))||day>daysInMonth[month]){ 
alert('Veuillez entrer un jour valide.'); 
return false; 
} 
if(strYear.length!=4||year==0||year<minYear||year>maxYear){ 
alert('Veuillez entrer une année &#65533; 4 chiffres comprise entre '+minYear+' et '+maxYear+'.'); 
return false; 
} 
if(dtStr.indexOf(dtCh,pos2+1)!=-1||isValidInteger(stripCharsInBag(dtStr,dtCh))==false){ 
alert('Veuillez entrer une date valide.'); 
return false; 
} 
return true; 
} 
function modifyDateFormat(dt){ 
var valuesTable=dt.value.split(dtCh); 
dt.value=valuesTable[1]+dtCh+valuesTable[0]+dtCh+valuesTable[2]; 
} 
function isEmail(emailAddress){ 
emailAddressValue=emailAddress.value.toLowerCase(); 
var countryTLDs=/^(ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|Fiddlesticks|bt|bv|bw|by|bz|ca|cat|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|eu|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|me|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|ps|pt|pw|py|qa|re|ro|rs|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|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$/;
var gTLDs=/^(aero|biz|cat|com|coop|edu|gov|info|int|mil|museum|name|net|org|jobs)$/; 
var basicAddress=/^(.+)@(.+)$/; 
var specialChars='\\(\\)><@,;:\\\\\\"\\.\\[\\]'; 


var validChars='\[^\\s'+specialChars+'\]'; 
var validCharset='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\'-_.'; 
var quotedUser='("[^"]*")'; 


var atom=validChars+'+'; 
var word='('+atom+'|'+quotedUser+')'; 
var validUser=new RegExp('^'+word+'(\.'+word+')*$'); 
var symDomain=new RegExp('^'+atom+'(\.'+atom+')*$'); 
var matchArray=emailAddressValue.match(basicAddress); 
if(emailAddress.value==''||emailAddress==null){ 
return true; 
} 
if(matchArray==null){ 
alert('L\'adresse Email semble incorrecte,\nveuillez vérifier la syntaxe.'); 
emailAddress.focus(); 
return false; 
}else{ 
var user=matchArray[1]; 
var domain=matchArray[2]; 
for(i=0;i2)&&(domArr[domArr.length-1].search(gTLDs)==-1)){ 
alert('L\'adresse Email semble incorrecte,\nveuillez vérifier le suffixe du domaine.'); 
emailAddress.focus(); 
return false; 
} 
if((domArr[domArr.length-1].length<2)||(domArr[domArr.length-1].length>6)){ 
alert('L\'adresse Email semble incorrecte,\nveuillez vérifier le suffixe du domaine.'); 
emailAddress.focus(); 
return false; 
} 
if(len<2){ 
alert('L\'adresse Email semble incorrecte.'); 
emailAddress.focus(); 
return false; 
} 
} 
return true; 
} 
String.prototype.trim = function() { return this.replace(/^\s*(\b.*\b|)\s*$/, "$1"); } 
function mandatoryText(input,fieldName){ 
if(input.value.trim()==''||input==null){ 
alert('Veuillez saisir '+fieldName+'.'); 
input.focus(); 
return false; 
} else { 
return true; 
} 
} 
function validForm(){ 
if(!mandatoryText(document.getElementById('EMAIL_FIELD'), 'Adresse e-mail')) return; 
if(!isEmail(document.getElementById('EMAIL_FIELD'))) return; 
if(!isDateOK(document.getElementById('DATEOFBIRTH_FIELD').value)) return; 
if(document.getElementById('DATEOFBIRTH_FIELD').value!='') modifyDateFormat(document.getElementById('DATEOFBIRTH_FIELD')); 
document.getElementById('emvForm').submit(); 
if(document.getElementById('DATEOFBIRTH_FIELD').value!='') modifyDateFormat(document.getElementById('DATEOFBIRTH_FIELD')); 
} 
</script> 
</head> 
 
<form name="emvForm" id="emvForm" action="http://p2tre.emv3.com/D2UTF8" method="POST" target="_top"> 
 
 
Adresse e-mail,
,

----

Prénom,
,

----

Nom,
,

----

Date de naissance,
,

----

Genre,
<select id="TITLE_FIELD" name="TITLE_FIELD">
<option selected value=""></option>
<option value="Homme">Homme</option>
<option value="Femme">Femme</option>
</select>,

----

 
</form> 
 
</html>

2 réponses

sapakus Messages postés 96 Date d'inscription mercredi 20 août 2003 Statut Membre Dernière intervention 10 février 2011 3
8 févr. 2011 à 22:51
Bonjour,

J'y connais rien en FBJS, mais je sais que rien ne t'empêche de mettre du JS dans le body, d'ailleurs le mieux dans ce cas est de le mettre à la fin du body (comme ça s'il y a des références dans le code JS aux éléments html de la page, il sait au moins de quoi on parle).
Donc mais le juste avant , bref à la fin quoi!

Sapakus
0
quinton75 Messages postés 44 Date d'inscription mercredi 13 octobre 2010 Statut Membre Dernière intervention 6 juillet 2011
8 févr. 2011 à 23:24
Oui j'avais deja essayé ça mais ça n'avait pas marcher...I

Il doit sans doute y avoir des choses à modifier mais tout ce que je vois en fbjs sur internet ne m'aide âs mais merci quand meme
0
Rejoignez-nous