javascript - Populating a form with names from a .txt file -


i trying populate dropdown list bunch of names stored in .txt in same directory html code. each name on new line of file and"names" id of dropdown store names.

upon loading page, list not populated @ all. guidance awesome.

<script type = "text/javascript"> window.onload = function () {     var select = document.getelementbyid("names");     var textfile = "/names.txt";             jquery.get(textfile, function(textfiledata) {           var eachlineintextfile = textfiledata.responsetext.split(",");         (var = 0, len = eachlineintextfile.length; < len; i++) {             var option = document.createelement('option');             option.text = option.value = eachlineintextfile[i];             select.add(option, 0);         };     }; }; </script> 

thanks!

it looks major issue needed better version of jquery. thank help!

<script type = "text/javascript">     window.onload = function () {         var select = document.getelementbyid("names");         var textfile = "/names.txt";                jquery.get(textfile, function(textfiledata) {               window.alert(textfiledata);              var eachname= textfiledata.split("\n");                   (var = 0, len = eachname.length; < len; i++) {                     var option = document.createelement('option');                     option.text = option.value = eachname[i];                     select.add(option, 0);         };        });     }; </script> 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -