DEMO of Adding options with default selection of current month
You can see the view-> Source of this page.
|
Adding elements to List box |
List box
Check the
selection of Date, Month & Year in our date project
JavaScript
<script language="javascript">
var dt=new Date();
var dt_month=dt.getMonth() +1;
//alert(dt_month);
function addOption(selectbox,text,value )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}
function addOption_list(){
var month = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
for (var i=0; i < month.length;++i){
addOption(document.drop_list.Month_list, month[i], month[i]);
if(i== dt_month){document.drop_list.Month_list.options[i].selected=true;}
}
}
</script>
HTML
<FORM name="drop_list" action="yourpage.php" method="POST" >
<SELECT NAME="Month_list">
<Option value="" >Month list</option>
</SELECT>
</form>
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
plus2net.com
|
|