JavaScript没有将用户名放在url中

时间:2013-11-22 01:10:37

标签: javascript

转到http://oxidepkz.net63.net/vote.php 这就是完整的php文件的样子,所以最糟糕的是我有一个用户名,假设进入一个mysql数据库。用户名是文本框,我想我只需要点击按钮的网址中的用户名,而不是实际的php页面。 以下是脚本代码的片段:

<script>
function next() {
if(document.vote.username.value.length == 0) {
    alert("The username field cannot be left empty.");
} else if(document.vote.username.value.length > 30) {
    alert("You've reached the maximum amount of characters.");
} else {
    document.vote.username.disabled = true;
    document.getElementById('button').style.display = "block";
    document.getElementById('nextbutton').style.display = "none";
}
}
 function changeAction(url) {
if(url.indexOf("rspscoding.org") != -1) {
    var username = document.vote.username.value;
    document.vote.action = ""+url+"&username="+username+"";
} else {
    document.vote.action = url;
}
  }
 </script>
 <title>Vote</title>
 </head>
 <body>
<center><br>
<br><br>
<div class="vote"><br><br>
<form name="vote" class="short style" method="post" target="_blank">
    <input name="username" type="text" size="30" maxlength="30"          placeholder="Username"><button id="nextbutton" type="button"     onClick="next();">Next</button>
    <div style="display: none;" id="button" class="button"><button type="submit" onClick="changeAction('http://www.rune-server.org/toplist.php?do=vote&sid=8289&name=');")>Rune-Server</button><button type="submit" onClick="changeAction('http://www.runelocus.com/toplist/index.php?action=vote&id=30838&id2=');")>RuneLocus</button></div>
</form><br>

1 个答案:

答案 0 :(得分:0)

从我看到的,当你的代码执行changeAction函数时,它会在URL中检查rspscoding.org。但是,您使用这两个按钮传入的URL无法参考rspscoding.org。因此,else语句被触发,而不是传递用户名,导致您的问题。
尝试删除if语句或将URL位置检查器更改为其他URL。如果这不起作用,我不知道会发生什么。祝你好运!