2013-11-22 24 views
-1

轉到http://oxidepkz.net63.net/vote.php 這就是完整的PHP文件看起來像什麼,所以最新錯誤是我有一個用戶名,假設進入MySQL數據庫。用戶名是文本框,我想我需要的是從按鈕點擊的URL中的用戶名,而不是實際的PHP頁面。 這裏是腳本代碼的片段:JavaScript不會把用戶名在URL

<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> 
+0

「請訪問http://oxidepkz.net63.net/vote.php」編號 –

+0

請不要評論某些無用的東西謝謝,它的鏈接可以查看完整的投票頁面,而不是評論「否「。 – Oxide

+0

請不要讓人們訪問您的隨機/粗略網站訪問您的問題的代碼。如果相關,請在此處發佈。 –

回答

0

從我所看到的,當你的代碼執行changeAction功能,它會檢查該URL rspscoding.org。但是,您使用這兩個按鈕傳遞的URL無處引用了rspscoding.org。因此,else語句正在觸發,而不是傳入用戶名,導致您的問題。
嘗試消除if語句或將URL位置檢查器更改爲不同的URL。如果這不起作用,我不知道會發生什麼。祝你好運!

+0

所以只是把整個if語句拿出來? – Oxide

+0

我會這麼認爲,除非你使用if語句是因爲特殊原因。如果是這樣,那麼將rspscoding.org更改爲實際位於傳遞給該函數的URL中的另一個URL。否則,是的,只要刪除整個if語句,並在if塊內部添加代碼即可。 – Atutouato

+0

你的意思是該網頁的網址?或點擊按鈕指向他們的網址? – Oxide