Soyez le premier à donner votre avis sur cette source.
Snippet vu 11 426 fois - Téléchargée 11 fois
function JSform (ObjectName , divTitle , mainDiv ){ this.targetValidation = ""; this.myID = "JSfrom"; this.myName = ObjectName; this.cursorElem=0; this.elemTitle = divTitle; this.elements= new Array(); this.motherDIVid = mainDiv; this.results = null; /**********************************************************/ this.addInput = function (sLib , sID){ this.elements[this.cursorElem]=new Array(); this.elements[this.cursorElem][0]=sID; this.elements[this.cursorElem][1] = (sLib == "" ? "" : sLib)+"<input type='text' onkeydown='"+(this.myName == "" ? "" : this.myName+".keyPressedHere()")+"' id='"+sID+"' />"; this.cursorElem++; } /**********************************************************/ this.addOpt = function (tOpt,sID){ for(i = 0 ; i < tOpt.length ; i++ ){ this.elements[this.cursorElem]=new Array(); this.elements[this.cursorElem][0]=sID + "_" + i; if(tOpt[i].length > 1 ){ this.elements[this.cursorElem][1] = "<label><input type='checkbox' id='"+sID+ "_" + i+"' value='"+tOpt[i][0]+"' onkeydown='"+(this.myName == "" ? "" : this.myName+".keyPressedHere()")+"'>"+tOpt[i][1]+"</label>"; } else { this.elements[this.cursorElem][1] = "<label><input type='checkbox' id='"+sID+ "_" + i+"' value='"+tOpt[i]+"' onkeydown='"+(this.myName == "" ? "" : this.myName+".keyPressedHere()")+"'>"+tOpt[i]+"</label>"; } this.cursorElem++; } } /**********************************************************/ this.start = function () { var elCont = document.getElementById(this.myID); if( elCont != null){ elCont.parentNode.removeChild(elCont); } elCont = document.createElement("div"); elCont.id = this.myID; document.getElementById(this.motherDIVid).style.opacity=0.4; elCont.style.display = "block"; // ... on l'affiche... elCont.style.position="absolute"; elCont.style.top="40%"; elCont.style.right="40%"; elCont.style.border="solid"; elCont.style.zIndex ="99"; var HTMLvalue = ""; if(this.elemTitle != ""){ HTMLvalue = "<h1>" + this.elemTitle + "</h1>"; } for(i = 0 ; i < this.cursorElem ; i ++){ HTMLvalue += this.elements[i][1]; } elCont.innerHTML =HTMLvalue; document.body.insertBefore(elCont, document.body.childNodes[0]); document.getElementById(this.elements[0][0]).focus(); } /**********************************************************/ this.doValidation = function() { this.results = new Array(); for(i = 0 ; i < this.cursorElem ; i ++){ this.results[this.elements[i][0]] = document.getElementById(this.elements[i][0]).value; } document.getElementById(this.motherDIVid).style.opacity=1; var elCont = document.getElementById(this.myID); elCont.parentNode.removeChild(elCont); if(this.targetValidation != ""){ this.targetValidation(); } } /**********************************************************/ this.keyPressedHere = function (e) { if(window.event.keyCode == 13) { for(i = 0 ; i < this.cursorElem ; i ++){ if( document.activeElement.id == this.elements[i][0]){ if( i == (this.cursorElem-1)){ this.doValidation( ); } else { document.getElementById(this.elements[i+1][0]).focus(); break; } } } } } }
<html> <head> <script> ..... CODE ... </script> </head> <body> <DIV ID="MAIN" style="position:relative;z-index:5;Width:80%;height:80%;background: none repeat scroll 0% 0% #000;"> </DIV> <script> var ot = new JSform("ot","titre","MAIN"); ot.addInput("test1","EDT1"); ot.addInput("test2","EDT2"); ot.addInput("test3","EDT3"); ot.start(); ot.targetValidation = function () { alert("oK!"); } </script> </body> </html>
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.