重定向不起作用

时间:2011-08-12 10:14:18

标签: javascript javascript-events velocity

我有一个包含以下代码的VM文件:

更新:                   输入表格                      #FW {                 display:none;             }                  

    function showSelect()
    {
        var post = document.getElementById('post');
        var fwork = document.getElementById('FW');

        fwork.style.display = post.selectedIndex == 1 ? 'block' : 'none';

    }

    function getMeThere(){
            var post = document.getElementById('post');
            var fwork = document.getElementById('frwork');
            if( post.value.toString() == "dpost"){
                document.forms["adform"].action="https://google.com" ;                  
                document.forms["adform"].method="post" ; 
            } 
            else{
                if(fwork.value.toString() == "wap"){
                    document.forms["adform"].action="https://mail.yahoo.com" ;
                    document.forms["adform"].method="post" ; 
                }
                else {
                    document.forms["adform"].action="bbc.co.uk" ;
                    document.forms["adform"].method="post" ; 
                }
            }
            document.forms["adform"].submit() ; 
        }
    </script>
</head>

<body>
    <form name="forum" id="adform" >
        <label>Payment Amount:</label>
        <input type = "text" name="paymentAmount" value=""/>
        <label> Reference:</label>
        <input type = "text" name="Reference" value=""/><br />
        <label>Choose post</label><br/>
        <select name="postCode" onchange="showSelect()" id = "post">
          <option value="dpost">Desktop post</option>
          <option value="mpost">Mobile post</option>
        </select><br/>
        <div id = "FW">
            <label>Choose Your Toolkit</label><br/>
            <select name="frwork" id = "frwork">
                <option id=""></option>
                <option id="jqm">jQuery Mobile</option>
                <option id = "wap">Webapp-Net</option>
                <option id = "tst">a Test</option>
            </select>
        </div>
        <input type="submit" onclick="getMeThere()"/>           
    </form>
</body>

重定向根本不起作用,我似乎无法找到问题。请注意,这些网址是假的,因为我可以发布真正的网址,因为安全问题。

1 个答案:

答案 0 :(得分:1)

错字?如果你改变了它会起作用:

document.forms[this].action

document.forms["adform"].action

修改

您还有var fwork = document.getElementById('FW');,然后fwork.value.toString(),但FW DIV 而不是SELECT

将选择更改为<select id="frwork" name="frwork">,并使用var fwork = document.getElementById('frwork');

进行阅读

修改2

您的fwork.value.toString() == "wap"将永远不会成为"WAP" <option id = "wap">w-Net</option> .value的唯一出现,而 <select name="frwork" id = "frwork"> <option value=""></option> <option value="jqm">jQuery Mobile</option> <option value = "wap">Webapp-Net</option> <option value = "tst">a Test</option> </select> 不是if (fwork.value.toString() == "wap") {

将HTML更改为:

if (fwork.options[fwork.selectedIndex].value == "wap") {

要阅读所选的,请替换:

{{1}}

使用:

{{1}}