开发者

onselect event in HTML <option></option> tag

Hi currently I have a list with onChange event in the <select>... Now I have two options as you can see in the code below. The option 55-rene got the selected="selected" property 开发者_运维问答so it is auto selected on page load. Now what I want is that when an option is auto selected (like it is below) this will work on selection (showSubCategories(this.value))

 <select name="category" id="category" size="12" 
                   onChange="showSubCategories(this.value)" >
    <option selected="selected" value="55-rene">Rene</option>
    <option value="55-kyle">Kyle</option>
    </select>


Trigger the Change Event of the SELECT on the page load.

Try this:

<script type="text/javascript">
    window.onload = function(){
        var category = document.getElementById("category");
        category.onchange();
    }
</script>


If I've understood your question correctly, then call showSubCategories(document.getElementById('category').value) when the page loads.

The onChange event won't fire when an item is set to be selected by default.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜