Skip to content Skip to sidebar Skip to footer

Capture Selected Item Value From A Select Drop Down List Created From A Text File Using Jquery

I have a text file that contains a few simple words like: make, this, work. I want to be able to load the text file and create a dynamic select drop down list from it. When the use

Solution 1:

Please replace:

$select.append('<option value="' + i + '">' + options[i] + '</option>"');

With this line:

$select.append('<option value="' + options[i] + '">' + options[i] + '</option>"');

This should fix your problem.

Solution 2:

You can simplify this a bit doing:

options.forEach(v => $select.append( new Option(v, v)))

Demo:

let options = 'one,two,three,four'.split(','), $select = $('#value');

options.forEach(v => $select.append( newOption(v, v)))
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><selectid="value"></select>

Post a Comment for "Capture Selected Item Value From A Select Drop Down List Created From A Text File Using Jquery"