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
Post a Comment