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
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
var withDOM = true;
function grpUpdate(liquid) {
var id = document.getElementById("Grp");
withDOM = document.getElementById("avecDOM");
withDOM = withDOM.options[withDOM.options.selectedIndex].value == '1'?true:false;
if( !withDOM ) {
var what = '';
switch(liquid) {
case 'cafe':
what = "<select name='liquidCafe' onchange='alert(this.options[this.options.selectedIndex].value)'><option value=''>-- Faites votre choix sans DOM --</option><option value='sucre'>Cafe sucre</option><option value='sans sucre'>Cafe sans sucre</option></select>";
break;
case 'cacao':
what = "<select name='liquidCacao' onchange='alert(this.options[this.options.selectedIndex].value)'><option value=''>-- Faites votre choix sans DOM --</option><option value='sucre'>Cacao sucre</option><option value='sans sucre'>Cacao sans sucre</option></select>";
break;
}
alert( document.getElementById("forma").length );
id.innerHTML = what;
alert( document.getElementById("forma").length );
} else {
while(id.hasChildNodes()) { id.removeChild(id.lastChild) }
var sel = document.createElement('select');
sel.setAttributeNode(document.createAttribute('name'));
var arr = [];
switch(liquid) {
case 'cafe':
sel.setAttribute('name','liquidCafe');
arr.push(['sucre','Cafe sucre']);
arr.push(['sans sucre','Cafe sans sucre']);
break;
case 'cacao':
sel.setAttribute('name','liquidCacao');
arr.push(['sucre','Cacao sucre']);
arr.push(['sans sucre','Cacao sans sucre']);
break;
}
sel.setAttributeNode(document.createAttribute('onchange'));
sel.setAttribute('onchange','alert(this.options[this.options.selectedIndex].value)');
sel.appendChild(document.createElement('option'));
sel.lastChild.setAttributeNode(document.createAttribute('value'));
sel.lastChild.setAttribute('value','');
sel.lastChild.appendChild(document.createTextNode('-- Faites votre choix avec DOM --'));
for(all in arr) {
sel.appendChild(document.createElement('option'));
sel.lastChild.setAttributeNode(document.createAttribute('value'));
sel.lastChild.setAttribute('value',arr[all][0]);
sel.lastChild.appendChild(document.createTextNode(arr[all][1]));
}
id.appendChild(sel);
}
return true;
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<FORM id="forma" METHOD=POST ACTION="">
<select id="avecDOM" name="avecDOM"><option value="0" selected>Sans DOM</option><option value="1">Avec DOM</option></select><br /><br />
Cafe : <INPUT TYPE="radio" NAME="radioGrp" value="cafe" onclick="return grpUpdate(this.value)" />
Cacao : <INPUT TYPE="radio" NAME="radioGrp" value="cacao" onclick="return grpUpdate(this.value)" />
<div id="Grp"></div>
<INPUT TYPE="submit" name="liquid" value="Envoyer" />
</FORM>
</BODY>
</HTML>
<?
if( isset($_POST['liquid']) ) {
foreach($_POST as $k => $v) {
echo $k." = ".$v."<br />";
}
}
?> |
Partager