skip to Main Content

I have a little problem. I can’t refresh the page when I select a parameter in the drop down list… When I tried it outside my page in a new document it was not a problem and I don’t know if it’s blocked somewhere by Bootstrap.. I’m still learning JS, so I might be making a mistake somewhere, but I have no idea where. I tried to reload one parameter see below and then I want to always reload the page when I click on the option value.. Thanks

Here is part of the code

 function reloadF(obj){
                var theVal = obj.options[obj.selectedIndex].value;
                if (theVal == 'reload1') location.reload();
              }
                    <select name="autnastranku" id="autnastranku" onchange="reloadF(this);">
                      <option value="0">Aut na stránku</option>
                      <option value="1">6</option>
                      <option value="2">9</option>
                      <option value="3">12</option>
                      <option value="reload1">reload</option>
                    </select>
                  

Image: Drop list with sorting options When I wanna reload the page if I click on reload, for example, see how I explain it

2

Answers


  1. Chosen as BEST ANSWER

    any ideas where the error might be? I have tried various attempts and simply clicking on select does not refresh the page.


  2. if you are using a external file for your js code you can perform the same like this, in the below code I am using a external script file for managing my js code and I thinks its the best approach to keep your js file away from other things.

    document.getElementById("autnastranku").addEventListener('input', function () {
      var theVal = this.value;
      if(theVal === 'reload1') {
          location.reload();
      }
    })
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
      <meta charset="UTF-8" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <title>Credit Card</title>
      <link rel="stylesheet" href="styles.css" />
    </head>
    
    <body>
      <select name="autnastranku" id="autnastranku">
        <option value="0">Aut na stránku</option>
        <option value="1">6</option>
        <option value="2">9</option>
        <option value="3">12</option>
        <option value="reload1">reload</option>
      </select>
    </body>
    <script src="script.js"></script>
    
    </html>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search