i want to populate a html list box (select tag) with the content of file (i.e each line of the file should become a single option in the list box (select element)).

suppose i have a file say

Code:

"load_lines.txt"

containing

Code:

s1.txt
s2.txt
s3.txt
s4.txt
s5.txt

there is a html form

Code:

<html>
<head>
<title>List box Loading</title>
</head>

<body>
<form id="frm1" name="frm1" action="" method="GET">

<select id="lb" name="lb" size="5">
</select><br /><br />

<input type="button" id="btn1" name="btn1" value="OK" />

</form>
</body>
</html>

when the form is loaded it should populate the list box (select element) with the contents of the file

Code:

"load_lines.txt"

.

can anyone tell how to do this using javascript?. please give the javascript code.

06-15-2013, 06:06 AM

Nicholas Diaz

Sorry no one replied to your thread. to be honest I am a little confused on what you are asking exactly. You want a box to populate a list of links that all are stored in a file?

or your saying you want a box to be on the screen and when someone clicks the button it populates the list of items in a list format?

try to be a little more clear and I would be more than happy to help you.

Whats your main objective here, be more descriptive, and why are you referring to javascript? Are you assuming you have to use it or are you wanting to know how to complete the task with javascript just for the sake of it?

06-17-2013, 04:03 PM

Nicholas Diaz

This would be very easy with php...
you could make each line of text a variable and then when you click the button in the form it could populate a list calling on each variable. or you could do this with ajax. if you wanted to get fancy with it.