按钮重定向

时间:2015-05-28 13:18:10

标签: php html button input

基本上我有一个文本框,我希望当人们在里面粘贴/写一个网站,然后按下按钮,用一个额外的参数重定向到网站(" / play / bonus")

<input name="website" id="website" type="text" />
<form method="POST" action=document.getElementById('website') & "/play/bonus">
    <input name="pn" value="bonus" type="hidden">
    <button id="bonus" class="btn btn-default navbar-element pull-center">
        <b>50</b> 
        Satoshis
    </button>

2 个答案:

答案 0 :(得分:0)

我会使用Javascript在代码中手动执行此操作,而不是使表单POST。

以下是您的示例:

<html>
<head>
    <title>JavaScript Form Redirection Example</title>
    <script type="text/javascript">
        function goToWebsite()
        {
            var url = document.getElementById("inputWebsite").value;
            if (url != null)
            {
                url += "/play/bonus";
                window.location.replace(url);
            }
        }
    </script>
</head>
<body>
<form>
<input type="text" id="inputWebsite" placeholder="Website address"/>
<input type="button" value="Go!" onClick="goToWebsite()"/>
</form>
</body>
</html>

非常简单,它的作用就是当点击按钮时,它会运行goToWebsite功能。

goToWebsite功能:

  1. 获取文本框中的URL值
  2. 检查以确保URL不为空
  3. 在其末尾添加/播放/奖励
  4. 使网络浏览器重定向到该页面。

答案 1 :(得分:-1)

document.getElementById('website')

将给出该元素的对象。您需要使用.value

document.getElementById('website').value

获取元素的值。

我认为没有必要使用javascript。如果您使用的是PHP 然后使用PHP的header函数重定向。

您的HTML:

<form method="POST" action="demo.php">
<input name="website" id="website" type="text" />
<input name="pn" value="bonus" type="hidden">
<input id="bonus" type="submit" class="btn btn-default navbar-element pull-center" Value="50 Satoshis">
</form>

您的 demo.php 文件将如下所示:

<?php
  $redirect = $_POST['website'];
  header("location:".$redirect."/play/bonus");