-4

I can not figure out how to call the function, yea().

Here is my code, currently:

<script>
  $(document).ready(function() {
    var myDate = new Date();

    function yea(){
      var year = myDate.getFullYear();
      for(var i = 1950; i < year+1; i++){
        return '<option value="'+i+'">'+i+'</option>';
      }
    }

    $(wrapper).append(
      <div class="form-group">
        <select name="from_year[]" class ="form-control"> '+yea()+' </select>
      </div>
    );
  }
</script>
Jonathan Lonowski
  • 121,453
  • 34
  • 200
  • 199
Yrtymd
  • 433
  • 2
  • 5
  • 16

1 Answers1

0

The problem here is not how you call yea, it is everything around it.

This would be fine:

append( some_string + yea() + some_string );

… but where you should have strings (which could be string literals or variables or any other JavaScript expression), you have raw HTML, which isn't allowed.

You seem to have missed the ' off from the start of the first string, and the other ' from the end of the second string, and inserted a raw new line in the middle of both (which is forbidden).

$(wrapper).append(
 '<div class="form-group"><select name="from_year[]" class ="form-control"> ' + yea() + ' </select></div>'
);
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335