admin管理员组

文章数量:1336643

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);

本文标签: javascriptreload page when item selected in ltselectgtHTMLStack Overflow