11549 sujets

JavaScript, DOM et API Web HTML5

Bonsoir à tous,

J'ai un énorme souci lorsque je crée une liste déroulante sous IE 8 et antérieure avec ce code :

var listOpt = document.createElement("option") ;
			listOpt.value = "" ;
			listOpt.text = "" ;	
			$(e).append(listOpt) ; 
			for(x=annee-100; x < annee-5; x++){ 
				listOpt = document.createElement("option") ;
				listOpt.value = x ;
				listOpt.text = x ;	
				$(e).append(listOpt) ;

La liste déroulante semble contenir des informations, mais elle sont vides.

Auriez-vous une idée svp ?

Merci d'avance.

bee
Modifié par beegees (29 May 2012 - 19:17)
Bonsoir beegees,

voici du code javascript qui insère dans un sélect d'autres options.
<!doctype html>
<html>
<head>
<title></title>
<script type="text/javascript">
/*==============================================================*/
/*     insertion d'une nouvelle option dans la boite select     */
/*==============================================================*/

function addOption(selectbox, value, text)
{
	var optn = document.createElement("OPTION");

	optn.text  = text;
	optn.value = value;

	selectbox.options.add(optn);
}

/*===================================================*/
/*     liste des insertions dans la boite select     */
/*===================================================*/

function insertion()
{
	var selectbox = document.getElementById("choix");

	addOption(selectbox, "choix2", "Choix 2");
	addOption(selectbox, "choix3", "Choix 3");
	addOption(selectbox, "choix4", "Choix 4");
}
</script>
</head>

<body onload="javascript:insertion();">
	<form>
		<select id="choix">
			<option value="choix1">Choix 1</option>
		</select>
	</form>
</body>
</html>


@+