开发者

JQuery onClick Pre-Populate

开发者 https://www.devze.com 2023-04-10 20:27 出处:网络
I am trying to do the following - could anyone help me out? I need to pre-populate the "Date" select dropdown from a comma delimited text field.

I am trying to do the following - could anyone help me out?

I need to pre-populate the "Date" select dropdown from a comma delimited text field.

<select id="place">
   <option>Manchester</option>
   <option>London</option>
</select>

<select id="date">
</select>

So basically this is what I am looking for ...

OnChange "listener" for Place, when "Place" changes it will get the text field "Place.txt" so fo开发者_JAVA技巧r example, if I select London, it will get "London.txt". This will contain a txt file with comma delimited values ie. Date1, Date2, Date3 etc.

This then needs to pre-populate the "Date" with each date.


$("#place").change(function(){
     var fileName = $("select option:selected").text() + ".txt";

     $.get(fileName, function(data) {
       var dates = data.split(",");
       var str = "";
       $.each(dates,function(index,value){
            str += "<option>"+value+"</option>";
       });
       $('#date').html(str);
     });
});

try this. untested you may have to play with it a little bit but this is the general idea

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号