그래서 나는 그것이 어떻게해야하는지 일하고 있습니다. 텍스트 박스, 라디오를 선택하고 모든 디스플레이를 올바르게 선택하십시오. 아무것도 넣지 않은 오류와 함께. 물건을 제출 한 후 임의의 텍스트를 표시해야합니다. 나는 운이 전혀 다른 것들을 시도했습니다. 배열을 시도했지만 그걸 잘못 처리했습니다. 이것은 .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가 필요합니다. –
제출하면 오류로 간주됩니다. – Chad
이것은 PHP가 HTML이 아니라는 의미입니다. – Chad