doushi1510 2016-10-19 01:50
浏览 44

使用DropDown值存储Var,然后使用该值打开给定的html

I have a dropdown menu with the values pulled out from my sql Db.

after selecting the value, it is stored in a variable.

Lets say that i choose an option "ABC" and this is stored into the variable, i then want to use this var for opening the html file on my localhost named ABC.html

Baiscily the objectiv is redirect the user to the web page related to his choice.

here is 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>

When i click the submit button it retrieves the selected option. How can i make it to redirect to any html select by the user?

  • 写回答

2条回答 默认 最新

  • dongzice4895 2016-10-19 02:10
    关注

    <html>
        <head>
        <script>
       
    function getOption() {
                obj = document.getElementById("choosedOP");
        document.getElementById("demo").innerHTML =
        obj.options[obj.selectedIndex].text;
    }
    function redirect(){
     obj = document.getElementById("choosedOP");
    var href = obj.options[obj.selectedIndex].text;
    window.location=href;
    }
    </script>
            <title>ComboBox Ajax, PHP y MySQL</title>
            <script src="includes/js.js"></script>
        </head>
    
        <body>
        <input type="button" id="redirect" value="redirect" onclick="redirect()">
            <select id="choosedOP">
            <option>http://wiki.com</option>
            <option>https://www.wikipedia.org/</option>
            </select>
            <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>

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊