Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display select option from dynamic data drop down list

My concept is to perform credit card validation.. In credit card year the data should be generated dynamically depending upon the current year.. it should show only upcoming years. Eg. We are in 2016.. So that the dropdown data will be display like 2016 to 2040.. the dropdown data is dynamic.. i have achieved it as well.. But, Here my problem is to display "select Option"

I want to show select option first for performing validation.. Give me some idea to do that.. Here is my sample code..

<select id="ccyear" name="ccyear"></select><br>
    <span>
    <script>
    var start =new Date().getFullYear();
    var end = new Date().getFullYear() + 24;
    var options = "";
	for(var year = start ; year <=end; year++)
	{
    options += "<option>"+ year +"</option>";
	}
	document.getElementById("ccyear").innerHTML = options;
    </script>
    </span>
like image 691
Nithya Avatar asked Jan 05 '23 04:01

Nithya


1 Answers

try to this...

<select id="ccyear" name="ccyear"></select><br>
    <span>
    <script>
   var start =new Date().getFullYear();
   var end = new Date().getFullYear() + 24;
   var options = "";
   var i = 0;
   for(var year = start ; year <=end; year++)
   {
	 if (i == 0){
		options += "<option selected>Select option</option>";
		i++;
	 } else {
		options += "<option value="+ year+">"+ year +"</option>";
     }

 }
document.getElementById("ccyear").innerHTML = options;
</script>
    </span>
like image 52
Pravin Vavadiya Avatar answered Jan 12 '23 03:01

Pravin Vavadiya