1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
<html>
<head>
<title></title>
<script type="text/javascript">
<!--
/** Auteur du script : 'Auteur' (www.developpez.com) **/
function addLigne(obj)
{
var i;
var elForm = document.getElementById("idFormulaire");
/*** Creation des input ***/
var elInput = new Array();
for (i=0;i<6;i++)
{
elInput[i] = document.createElement("input");
elInput[i].type = "text";
//elInput[i].name="";
//elInput[i].id="";
}
/*** Creation des textNode ***/
var elTxt = new Array();
var tabTxt = new Array(" id Div "," Width "," Height "," Position "," Top "," Left "," Texte ");
for (i=0; i<tabTxt.length; i++)
{
elTxt[i] = document.createTextNode(tabTxt[i]);
}
/*** Creation de la liste et de ses options ***/
var elSelect = document.createElement("select");
//elSelect.name="";
//elSelect.id="";
/*** Creation des options ***/
/*** syntaxe : Option("Text","Value",false,false); ***/
var elOption = new Array(
new Option("","",false,false),
new Option("absolute","absolute",false,false),
new Option("fixed","fixed",false,false),
new Option("inherit","inherit",false,false),
new Option("relative","relative",false,false)
);
/*** Insertion des input et des textes dans le document (1ere partie) ***/
for (i=0;i<3;i++)
{
elForm.insertBefore(elInput[i], obj.parentNode);
elForm.insertBefore(elTxt[i], obj.parentNode);
}
/*** Insertion du select dans le document ***/
/*** Attention IE : il faut inserer le select dans le document avant d ajouter
**** les options ***/
elForm.insertBefore(elSelect, obj.parentNode);
for (i=0;i<elOption.length;i++)
{
elSelect.options.add(elOption[i]);
}
elForm.insertBefore(elTxt[3], obj.parentNode);
/*** Insertion des input et des textes dans le document (2eme partie) ***/
for(i=3;i<6;i++)
{
elForm.insertBefore(elInput[i], obj.parentNode);
elForm.insertBefore(elTxt[i+1], obj.parentNode);
}
/*** Ajout de sauts de lignes ***/
elForm.insertBefore(document.createElement("br"), obj.parentNode);
elForm.insertBefore(document.createElement("br"), obj.parentNode);
}
//-->
</script>
</head>
<body>
<form id="idFormulaire" action="" method="post">
<input name="div" type="text" /> id div
<input name="width" type="text" class="inputpx" /> width
<input name="height" type="text" class="inputpx" /> height
<select name="position">
<option value=""></option>
<option value="absolute">absolute</option>
<option value="fixed">fixed</option>
<option value="inherit">inherit</option>
<option value="relative">relative</option>
</select>position
<input name="top" type="text" class="inputpx" /> top
<input name="left" type="text" class="inputpx" /> left
<input name="text" type="text" /> text
<br><br>
<div>
<br />
<input value="Ajouter un élément" name="checkmore" type="button" onclick="addLigne(this);" /><br />
<br />
</div>
<input name="creer" type="submit" value="creer" />
</form>
</body>
</html> |