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>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With