Select ajax DOM Fill


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <html>
  2. <head>
  3. <title>Select ajax DOM Fill</title>
  4. <script type="text/javascript" src="XHConn.js"></script>
  5. </head>
  6. <body>
  7. <script type="text/javascript">
  8. function fill( ) {
  9. var fnCarica = function (oGet) {
  10. objSelect = document.getElementById('elemento-select') ;
  11. var sJSON = oGet.responseText;
  12.  
  13. var oJSON = eval(sJSON);
  14. var nOpt
  15. for( nOpt=0;nOpt<oJSON.length;nOpt++) {
  16. objSelect.options[objSelect.options.length] = new Option( oJSON[nOpt].text , oJSON[nOpt].value )
  17. };
  18. };
  19. new XHConn().connect('fill.txt', 'GET', '' , fnCarica);
  20. }
  21. </script>
  22. <select id="elemento-select">
  23. <option value="valore1">etichetta1</option>
  24. <option value="valore2">etichetta2</option>
  25. <option value="valore3">etichetta3</option>
  26. </select>
  27. <button onclick="fill()">bau</button>
  28. </body>
  29. </html>

URL: http://maurizio.mavida.com/2005/11/27/modificare-le-select-con-dom-javascript-e-ajax/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.