/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<html> <head> <title>Select ajax DOM Fill</title> <script type="text/javascript" src="XHConn.js"></script> </head> <body> <script type="text/javascript"> function fill( ) { var fnCarica = function (oGet) { objSelect = document.getElementById('elemento-select') ; var sJSON = oGet.responseText; var oJSON = eval(sJSON); var nOpt for( nOpt=0;nOpt<oJSON.length;nOpt++) { objSelect.options[objSelect.options.length] = new Option( oJSON[nOpt].text , oJSON[nOpt].value ) }; }; new XHConn().connect('fill.txt', 'GET', '' , fnCarica); } </script> <select id="elemento-select"> <option value="valore1">etichetta1</option> <option value="valore2">etichetta2</option> <option value="valore3">etichetta3</option> </select> <button onclick="fill()">bau</button> </body> </html>
URL: http://maurizio.mavida.com/2005/11/27/modificare-le-select-con-dom-javascript-e-ajax/