javascripthtmlshtml

reload page when item selected in <select> - HTML


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?


Solution

  • 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/