提交表单有随机文本

时间:2014-10-12 01:46:59

标签: javascript

所以我知道一切都在发挥作用。文本框,收音机并选择所有正确显示。以及没有放任何东西的错误。我需要在提交内容后显示随机文本。我尝试过不同的东西,但没有运气。我尝试了一个阵列,但我做错了。这是.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>

1 个答案:

答案 0 :(得分:0)

您想在哪里显示该文字?

您可以尝试:

提醒(&#39;随机文字&#39;);

或者也许:

document.getElementById(&#34; errMess&#34;)。追加(&#34; 您的信息已提交&#34;);