i am a relativly new to prgramming, and currently stuck on a problem. Thanks for the feedback, I have used google and looked over many similar questions on stack overflow, they all seem to give answers for importing values from html dropdowns to JavaScript, while I need the exact opposite, I have been looking for an answer for a few hours now, I just though that I should ask here directly after searching for so long. Currently I have coded dropdowns in html, I would like to write a script in JavaScript that would convert values in a text file on the local computer into dropdowns in html format. I have tried FileReader and XMLHttpRequest(); but to no avail Here is my HTML code:
<optgroup id="Plants" label="plants">
<option type="checkbox" id="plant_1" name="plant_1" value="Plant1">Plant1</option>
<option type="checkbox" id="plant_2" name="plant_2" value="Plant2">Plant2</option>
<option type="checkbox" id="plant_3" name="plant_3" value="Plant3">Plant3</option>
</optgroup>
<optgroup id="Animals" label="animals">
<option type="checkbox" id="Animal_1" name="Animal_1" value="Animal1">Animal1</option>
<option type="checkbox" id="Animal_2" name="Animal_2" value="Animal2">Animal2</option>
<option type="checkbox" id="Animal_3" name="Animal_3" value="Animal3">Animal3</option>
</optgroup>
my script is along the lines of:
$.Get("TestFile.txt", function k(data){
var lines = data.split('/n');
}
var dropdown = $('Plants');
for(var i =0; i < lines.length; i++) {
var count = lines[i];
$('dropdown').append(count);
}
return lines;
});
What the testfile.txt file will look like:
Plants -
Rose
Bannana
Blackberry
Animals -
Lion
Cow
Elephant