Use stored value and redirect to chosen page

Asked

Viewed 151 times

1

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

Let’s say I choose an option "ABC" and save it in a variable, then I want to use this variable to open a file html called ABC.html on my localhost.

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

here 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 use the "click Me" button to redirect the user to the chosen page ? That is, use the value of the var obj and open the page with the stored name.

For example, when choosing the ABC option, it is redirected to a localhost/abc.html page ?

  • 1- What is the content of js.js ? 2- I see a tag closure </form>, but I don’t see its opening. 3- I can’t identify the identifier choosedOP. And ending this should not be accomplished through the element select?

  • This code works as intended. It selects the elements of the 3 ops and indicates the chosen op by clicking me. That’s not the problem. Now, instead of indicating the chosen op, I intended that by clicking the click me button, the user would be redirected to the page with the name of var obj. I know I have to replace/add the window.Location command.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.