html - Runnning javascript for dropdown on page load? -
i have js function controls appearnace of select element upon change. however, 1 thing need code run start when element loads selected options class should have been applied.
css:
select {height: 50px; width: 80px; border: solid 1px #c8c8c8; color:rgba(0, 0, 0, 0);} select:focus, #select:focus { color:black; } .lightgrey {background: lightgrey} .green {background:green} .orange {background:orange} .yellow {background:yellow} .red {background:red} .purple {background:purple}
javascript:
function colourfunction(select) { var colour = select.options[select.selectedindex].classname; select.classname = colour; select.blur(); }
select:
<select class="selectelement" runat="server" id="dropdown_" onchange="colourfunction(this)"> <option selected="selected" class="lightgrey" value="n">n</option> <option class="green" value="g">g</option> <option class="orange" value="o">o</option> <option class="yellow" value="a">a</option> <option class="red" value="r">r</option> <option class="purple" value="u">u</option> </select>
i want class n applied on load color:rgba(0, 0, 0, 0);
if you're using jquery:
$(function(){ //all onload actions want });
if want stick pure js
document.onreadystatechange=function(){ //all onload actions want }
Comments
Post a Comment