Use stored value and redirect to chosen page

1

I have a dropdown list that takes its options from a mysql database. The value is stored in a variable with the Script Js. The button returns the information selected in option 3. After selecting the value it is saved in a variable.

Let's say I choose an "ABC" option and save it to a variable, so I want to use this variable to open a html file named ABC.html in my localhost.

Basically the goal is to redirect the user to the page relating to your choice.

Here's my Script:

<html>
    <head>
    <script>
function getOption() {
    var obj = document.getElementById("choosedOP");
    document.getElementById("demo").innerHTML =
    obj.options[obj.selectedIndex].text;
}
</script>
        <title>ComboBox Ajax, PHP y MySQL</title>
        <script src="includes/js.js"></script>
    </head>

    <body onload="getOp1();">

        <div id="op1"></div> <br />

        <div id="op2"></div> <br />

        <div id="op3"></div>
        <input type="button" onclick="getOption()" value="Click Me!">
    </form>

    <p id="demo"></p>
</body>
</html>

How can I do, by clicking the "click me" button, the user will be redirected to the chosen page? That is, using the value of var obj and open the page with the name stored.

For example, when you choose the ABC option, you are redirected to a localhost / abc.html page?

    
asked by anonymous 19.10.2016 / 04:36

1 answer

0
    function redirect()
{
    var obj = document.getElementById("cbx_localidad");
    var redir =obj.options[obj.selectedIndex].text;
    window.location.href = redir;
      }

It was as simple as this

    
20.10.2016 / 08:07