最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - reload page when item selected in <select> - HTML - Stack Overflow

programmeradmin1浏览0评论

I have a small issue regarding the use of a <select></select>

I receive data from a server with an request. For this request I used shtml.

Now what I want is that when an user selects an item in de selectbox the page gets the data of that item from the server. An request to the server can look like this %! tcp-connections

So what I think i have to do is an page refresh with JavaScript or something like that. Can someone tell me how I can do this?

I have a small issue regarding the use of a <select></select>

I receive data from a server with an request. For this request I used shtml.

Now what I want is that when an user selects an item in de selectbox the page gets the data of that item from the server. An request to the server can look like this %! tcp-connections

So what I think i have to do is an page refresh with JavaScript or something like that. Can someone tell me how I can do this?

Share Improve this question edited Sep 18, 2014 at 7:50 ashokhein 1,05813 silver badges38 bronze badges asked Sep 18, 2014 at 7:10 user3996249user3996249
Add a ment  | 

3 Answers 3

Reset to default 4

HTML:

<select id="select">
    <option selected>Default</option>
    <option value="refresh">Refresh</option>
</select>

JavaScript:

function onchange(e) {
    if (e.currentTarget.value === 'refresh') {
        window.location.reload();
    }
}

document.getElementById('select').addEventListener('change', onchange);

Demo: http://jsfiddle/w425208t/

Use window.location.href = yourUrl; It will "redirect" you to page with url yourUrl

you can use any of these :

window.location.reload(false); 
// If we needed to pull the document from
//  the web-server again (such as where the document contents
//  change dynamically) we would pass the argument as 'true'.
//i.e. 'true' will force the page to reload from the server. 'false' will reload from cache, if available.

or 

location.reload(); 

or 

window.location.replace(window.location.pathname);
发布评论

评论列表(0)

  1. 暂无评论