I need to make script that creates drop-down list from text file (new line in text file – new line in drop-down list). Somebody told me that I should use XMLHttpRequest for that, so I have found on internet script that can write content from text file on screen, but I don’t know how to modify it to write it in drop-down list. How to add reference.value to make values for drop-down? This is it: <html> <head> <title>XMLHttpRequest Object GET Request</title> </head> <body> <script language="javascript" type="text/javascript"> <!-- // request variable var request_var; // Request object method wrapper function function request_object() { try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) { try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) { return new XMLHttpRequest(); } } } // Call the request object method wrapper function request_var=request_object(); if(!request_var) { alert("Your Web browser does not support the XMLHttpRequest object."); } function load() { if(request_var.readyState==4) { document.getElementById('elements_id').innerHTML=request_var.responseText; } } function call() { if(request_var) { d=document; request_var.open("GET","textfile.txt",true); request_var.onreadystatechange=load; request_var.send(null); } } //--> </script> <div id="elements_id"></div> <a onclick="call()" href="#">XnMLHttpRequest Object GET Request</a> </body> </html> Code (markup):
You have to change this part: document.getElementById('elements_id').innerHTML=request_var.responseText; request_var.responseText is the text of the file. This script just dumps it onto the page. You have to process it by splitting it up into separate values (like option1 of the dropdown, option 2, option 3, etc). The simply output it as html: [select name="mySelect"][option]option 1[option]option 2[/select] etc