-4
strPropertyEvents=20 Aug 2014-New Activity 1, 21 Aug 2014-gfdbfjdb ,21 Aug 2014-anubhav, 24 ug 2014-hjdf

Basically In strPropertyEvents it is stored in the form of string but I want to split this string in such a manner that where there is a comma , it splits down there and the output is in a dropdown list as

<script type="text/javascript">
$('#hiddenActivityDate').val('@strPropertyEvents');
alert($('#hiddenActivityDate').val());
var strList = hiddenActivityDate.split(',');
console.log(strList);
$.each(strList,function(index,val){
$("#ProgramList").append('<option>'+val+'</option>');
});
</script>

But the code is not working. Could you please help me out what is the mistake either in fiddle or anywhere.

Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
user3756425
  • 117
  • 1
  • 2
  • 7

2 Answers2

0

I don't find the definition of hiddenActivityDate

<script type="text/javascript">
$('#hiddenActivityDate').val('@strPropertyEvents');
var hiddenActivityDate = $('#hiddenActivityDate').val();
var strList = hiddenActivityDate.split(',');
console.log(strList);
$.each(strList,function(index,val){
  $("#ProgramList").append('<option>'+val+'</option>');
});
</script>
Farkhat Mikhalko
  • 3,565
  • 3
  • 23
  • 37
0

I'm not quite sure where you get the string from, but I've added a working example where the string is declared at the top, as well as in a hidden input field.

<script type="text/javascript">
$(document).ready(function(){

    var strPropertyEvents="20 Aug 2014-New Activity 1, 21 Aug 2014-gfdbfjdb ,21 Aug 2014-anubhav, 24 ug 2014-hjdf";
    $('#hiddenActivityDate').val(strPropertyEvents);
    var strList = strPropertyEvents.split(',');
    console.log(strList);
    $.each(strList,function(index,val){
        $("#ProgramList").append('<option>'+val+'</option>');
    });
});
</script>


<input id="hiddenActivityDate" type="hidden" />

<select id="ProgramList"></select>

fiddle

msfoster
  • 2,474
  • 1
  • 17
  • 19