所以我有一切工作如何需要。文本框,收音机并选择所有正确显示。以及没有放入任何东西的错误。我需要在提交东西后显示一个随机文本。我尝试过不同的事情,但没有运气。我尝试了一个数组,但是我做了一些错误的处理。这是一个.php扩展名。任何想法提交表单有随机文本
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Ex 2</title>
<link href="styles.css" rel="stylesheet">
<script>
function checkForm(){
var chk = true;
var mName = document.getElementById("txtM");
var meth = document.getElementById("methM");
var rad = document.getElementById("radM");
var sel = document.getElementById("selM");
var heal = document.getElementById("a");
var dark = document.getElementById("b");
var ele = document.getElementById("c");
var wep = document.getElementById("imp");
meth.setAttribute("style", "display:none");
rad.setAttribute("style", "display:none");
sel.setAttribute("style", "display:none");
if (mName.value=='no'){
document.getElementById("methM").innerHTML = "No";
meth.setAttribute("style", "display:inline");
chk = false;
}
if (mName.value=='yes'){
document.getElementById("methM").innerHTML = "Yes";
meth.setAttribute("style", "display:inline");
chk = false;
}
if (mName.value==''){
document.getElementById("methM").innerHTML = "So You Don't Like To Do Any Damage?";
meth.setAttribute("style", "display:inline");
chk = false;
}
if (heal.checked) {
document.getElementById("radM").innerHTML = "Healer";
rad.setAttribute("style", "display:inline");
chk = false;
}
if (dark.checked) {
document.getElementById("radM").innerHTML = "Dark";
rad.setAttribute("style", "display:inline");
chk = false;
}
if (ele.checked) {
document.getElementById("radM").innerHTML = "One with the Elements";
rad.setAttribute("style", "display:inline");
chk = false;
}
if (wep.value==1){
document.getElementById("selM").innerHTML = "Rifle";
sel.setAttribute("style", "display:inline");
chk = false;
}
if (wep.value==2){
document.getElementById("selM").innerHTML = "Bow and Arrow";
sel.setAttribute("style", "display:inline");
chk = false;
}
if (wep.value==3){
document.getElementById("selM").innerHTML = "Daggers";
sel.setAttribute("style", "display:inline");
chk = false;
}
if (wep.value==0){
document.getElementById("selM").innerHTML = "Gotta Have A Weapon!";
sel.setAttribute("style", "display:inline");
chk = false;
}
}
</script>
</head>
<body>
<div class="page">
<main role="main">
<article>
<div id="errMess" class="errMess"></div>
<h1>What Guild Wars 2 Profession Are You</h1>
<div class="cssTable" style="margin-top:-25px;">
<form method="post">
<table>
<tr><td colspan="3"></td></tr>
<tr>
<td><div align="right">Do you like to do high damage?</div></td><td width="217">
<input id="txtM" name="txtM" type="text" size="25"></td><td ><div id="methM" style="display:none"></div></td></tr>
<tr>
<td><div align="right">What best describes you?</div></td><td>
<input id="a" type="radio" name = "group1" value="A">Healer</input>
<input id="b" type="radio" name = "group1" value="B">Dark</input>
<input id="c" type="radio" name = "group1" value="C">Earthling</input>
</td><td><div id="radM" style="display:none"></div></td>
</tr>
<tr>
<td>What weapon would you like to have?</td>
<td>
<select id="imp"><option value="0" selected="true">Select One</option>
<option value="1">Rifle</option>
<option value="2">Bow and Arrow</option>
<option value="3">Daggers</option></select>
</td><td><div id="selM" style="display:none"></div></td>
</tr>
<tr><td colspan="3" align="right"><input type="button" class="styled-button-7" value="Send" onclick="checkForm()"/></td></tr></table></form></div></article>
</main></div>
</body>
</html>
我不明白...当您提交表单时,页面将被重新加载。因此,您的js脚本将再次侦听表单的提交事件。你需要在PHP中生成这条消息,或者如果你想使用JS,你需要AJAX – 2014-10-12 01:55:33
我有它一旦提交它就算错误 – Chad 2014-10-12 04:04:18
这是PHP不是HTML,如果多数民众赞成什么意思 – Chad 2014-10-12 04:14:00