reload page when item selected in <select> - HTML

user3996249 picture user3996249 · Sep 18, 2014 · Viewed 7.5k times · Source

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?

Answer

Miguel Mota picture Miguel Mota · Sep 18, 2014

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.net/w425208t/