开发者

How to prevent dropdown on Android submit form when the first value is selected

I'm building a mobile website. I use regular html for the dropdown like below. If I select the dropdown on Android and click on "Category", it tries 开发者_运维技巧to submit the form. But iPhone doesn't do anything which is the desired behavior I want. I found a similar post here, but I'm not building an app. Some websites use links instead of dropdown, but it's not an option for me. Any suggestion or way around it? Thanks!

<select onchange="document.form.submit();">
   <option>Category</option>
   <option value="1">1</option>
   <option value="2">2</option>
</select>


I would recommend revising your logic to not submit on change if that isn't your desired behavior. You may want to make a function that inspects the selected option on change before submit to decide whether or not to submit.

Something like below..

<select onchange="dropDownChange(this);">
   <option>Category</option>
   <option value="1">1</option>
   <option value="2">2</option>
</select>

function dropDownChange(element){
    if(element.selectedIndex != 0){
        document.form.submit();
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜