我需要在使用HTML和Javascript后,将表单上提交的输入显示在页面上

我需要在使用HTML和Javascript后,将表单上提交的输入显示在页面上,javascript,html,Javascript,Html,我需要一个我正在创建的页面来获取提交的信息,然后在按下提交时将其显示在页面上。按照我现在的方式,它会打印姓名、电子邮件、工作经验、日期、参考资料和其他评论。选择的补偿和区域打印为未定义 请帮忙 <script type="text/javascript"> info = document.getElementById("personalInfo"); info.innerHTML = "<strong>Peronal Info: </strong>"

我需要一个我正在创建的页面来获取提交的信息,然后在按下提交时将其显示在页面上。按照我现在的方式,它会打印姓名、电子邮件、工作经验、日期、参考资料和其他评论。选择的补偿和区域打印为未定义

请帮忙

<script type="text/javascript">
info = document.getElementById("personalInfo");
    info.innerHTML = "<strong>Peronal Info: </strong>" + "<br>" + "Name: " + 
                    document.feedback.fname.value +
                    " " +
                    document.feedback.lname.value +
                    "<br>" + "Email: " +
                    document.feedback.email.value;

    info = document.getElementById("experienceSubmit");

    var compensationValue,regionValue;
    //Get compensation value
    for(var i=0;i<document.feedback.comp.length;i++){
        if(document.feedback.comp[i].checked){
        compensationValue = document.feedback.comp[i].value;
    }
}
    //Get region value
    for(var i=0;i<document.feedback.region.length;i++){
        if(document.feedback.region[i].checked){
        regionValue = document.feedback.region[i].value;        
    }
}


info = document.getElementById("otherSubmit");
    info.innerHTML = "<strong>Other information: </strong>" + "<br>" + "# of References " + 
                    document.feedback.reference.value +
                    "<br>" + "Additional Comments: " +
                    document.feedback.comments.value; 
return false;
}
</script>
</head>
<body background="../Assignment 5/_images/abstract_color_background_picture_8016-wide.jpg" >
<form   name="feedback" method="post" onSubmit="return checkform()">
        <section  id="pinfo" class="inputArea">
        <fieldset>
            <table>
                <tr>
                    <td>Last Name: </td>
                    <td><input name="lname"
                               type="text"
                               autofocus
                               required
                               placeholder="lname"                               
                               size="25" />
                    </td>
                </tr>                   
                <tr>
                    <td>First Name: </td>
                    <td><input name="fname"
                               type="text"
                               size="25"
                               required
                               placeholder="fname" />
                    </td>
                </tr>
                <tr>
                    <td>Email: </td>
                    <td><input name="email"
                               type="email"
                               size="40"
                               required
                               placeholder="....@hotmail.com" />
                     </td>
                </tr>
                    <td>Gender: </td>
                    <td><select name="gender">
                            <option selected disabled style='display:none;'>
                            Gender</option>                         
                            <option value="Male">Male</option>
                            <option value="Female">Female</option>                      
                        </select>

                </td>
                </tr>
            </table>
            </fieldset>
</section>
<section id="experience">
            <fieldset>
            <table>
                <tr>
                    <td>
                    <label for="experience">Years of Experience: </label>
                    <input name="experience" type="number" />
                  </td>
              </tr>
              <tr>
                    <td>
                        <label for="date">Date</label>
                        <input name="date" type="date" />
                    </td>
              <tr>
                    <td>
                        <label for="comp">Compensation: </label><br>
                        <input name="comp" type="radio" id="Salary" value="Salary Selected">Salary &nbsp;
                        <input name="comp" type="radio" id="SalaryWB" value="Salary with bonus Selected">Salary with Bonus &nbsp;
                        <input name="comp" type="radio" id="Commission" value="Commission Selected">Commission &nbsp;
                    </td>
              </tr>
              <tr>
                <td>
                    <label for="region">Region: </label><br>
                    <input name="region" type="checkbox" id="East" value="East Selected">East &nbsp;
                    <input name="region" type="checkbox" id="West" value="West Selected">West &nbsp;
                    <input name="region" type="checkbox" id="North" value="North Selected">North &nbsp;
                    <input name="region" type="checkbox" id="South" value="South Selected">South &nbsp;
                </td>
              </tr>
          </table>
          </fieldset>
</section>
<section id="other">
<fieldset>
          <table>
            <tr>
                <td>
                <label for="reference">References<br>0&nbsp;&nbsp 1 &nbsp;&nbsp 2 &nbsp&nbsp 3 &nbsp&nbsp 4 &nbsp&nbsp 5<br></label>
            <input name="reference" id="reference"
                    type="range" 
                    value="0"
                    min="0"
                    max="5"
                    step="1" />
                </td>
            </tr>
            <tr>
                <td>
                    <label for="comments">Additional Comments: <br></label>
                    <textarea 
                    name="comments"
                    rows="5" 
                    cols="20" 
                    placeholder="Please include any other pertinent information here"></textarea>                   </td>
            </tr>          
          </table>          
</fieldset>

        <input type="submit" value="Submit" />
        <input type="reset" value="Clear" />
</section>
</form>
<section id="personalInfo"></section>
<section id="experienceSubmit"></section>
<section id="otherSubmit"></section>
</body>

info=document.getElementById(“personalInfo”);
info.innerHTML=“个人信息:“+”
“+”姓名:“+ document.feedback.fname.value+ " " + document.feedback.lname.value+ “
”+“电子邮件:”+ 文件、反馈、电子邮件、价值; info=document.getElementById(“experienceSubmit”); 无功补偿值,区域值; //获得补偿值
对于(var i=0;i您用于获取复选框和单选按钮的值的方法是错误的。您可以使用这段代码获取单选按钮或复选框的选中值

单选按钮

var radios = document.getElementsByName('comp');

for (var i = 0, length = radios.length; i < length; i++) {
    if (radios[i].checked) {
        // do whatever you want with the checked radio
        alert(radios[i].value);

        // only one radio can be logically checked, don't check the rest
        break;
    }
}
var checkedValues = []; 
var inputElements = document.getElementsByName('region');
for(var i=0; inputElements[i]; ++i){
      if(inputElements[i].checked){
           checkedValues.push(inputElements[i].value);   
      }
}
var str = checkedValues.ToString(); // all the selected regions in a string.

您可以在集合中循环并检查它是否被选中

此代码适用于以下情况:

for(var i=0;i<document.feedback.comp.length;i++){
    if(document.feedback.comp[i].checked){
        alert(document.feedback.comp[i].value)
    }
}

用于(var i=0;我发现其他注释不起作用,因为我忘记了a+。其他所有不起作用的注释都是因为相同的原因。我添加了所有的+。现在补偿和区域打印未定义。是否有特殊的方法打印单选按钮和复选框?是否使用jquery?谢谢,我如何在代码中保留f我现在拥有的ORMATING?我是否从复选框中获取值并将其放入如下代码中?document.feedback.str.value您可以将这两个值放入函数中,然后用函数调用替换
document.feedback.region.value
document.feedback.comp.value
您是否使用Java?我无法实现此功能,当我调用该函数时,它会闪烁信息,然后什么也不显示。这是可行的,但如何将选中的内容分配给值,以便我可以在选中的“
”+”补偿区“+document.feedback.comp.value+”
“+”中打印它:+document.feedback.region.value;”语句?如果可能,我也不希望它有一个弹出窗口。这只输出一个复选框,如何使其输出所有选中的框。
for(var i=0;i<document.feedback.region.length;i++){
    if(document.feedback.region[i].checked){
        alert(document.feedback.region[i].value)
    }
}
info = document.getElementById("experienceSubmit");

var compensationValue,regionValue;
   //Get compensation value
   for(var i=0;i<document.feedback.comp.length;i++){
        if(document.feedback.comp[i].checked){
            compensationValue = document.feedback.comp[i].value;
        }
    }
   //Get region value
 for(var i=0;i<document.feedback.region.length;i++){
        if(document.feedback.region[i].checked){
            regionValue = document.feedback.region[i].value;
        }
    }

 info.innerHTML = "<strong>Experience and Salary: </strong>" + "<br>" + "Years of experience: " + 
                    document.feedback.experience.value +
                    "<br>" + "Date of availability: " +
                    document.feedback.date.value +
                    "<br>" + "Compensation Chosen: " +
                    compensationValue +
                    "<br>" + "Region Selected: " +
                    regionValue;