Changes

Add Options to a Combo Box Using JavaScript

95 bytes added, 15:30, 12 June 2014
no edit summary
function clearTimes()
{
if (var frm = document.forms[0];// at Level 1 use document.form1 instead of document.forms[0] if (frm.startdate.value=="")//this will only run if there is not startdate already saved
{
try
{
document.forms[0]frm.starthour.add(new Option("", "", true, true), document.forms[0]frm.starthour.options[0]) //add blank option to beginning of starthour document.forms[0]frm.startminute.add(new Option("", "", true, true), document.forms[0]frm.startminute.options[0]) document.forms[0]frm.endhour.add(new Option("", "", true, true), document.forms[0]frm.endhour.options[0]) document.forms[0]frm.endminute.add(new Option("", "", true, true), document.forms[0]frm.endminute.options[0])
}
catch(e)
{ //in IE, try the below version instead of add()
document.forms[0]frm.starthour.add(new Option("", "", true, true), 0) //add blank option to beginning of starthour document.forms[0]frm.startminute.add(new Option("", "", true, true), 0) document.forms[0]frm.endhour.add(new Option("", "", true, true), 0) document.forms[0]frm.endminute.add(new Option("", "", true, true), 0)
}
}
}
clearTimes();
 
</pre>
'''Note:''' the same syntax can be used at Level 1, replacing '''document.forms[0]''' with '''document.form1''' ==See Also==* [[Remove Options from a Combo Box Using JavaScript]]* [[Conditional Lists of Values]]
[[Category:JavaScript]]
8,849
edits