html页面内的输出表单
Output form within html page
我想在html表单下面的同一页面中打印提交的输入元素。选中的复选框元素应该全部打印出来。可以避免使用image元素
这个函数似乎不工作。
function validateForm(myForm) {
var a = document.getElementById("fname").value;
document.getElementById("display").innerHTML = y;
var b = document.getElementByName("passwords").value;
document.getElementById("display1").innerHTML = y;
var c = document.getElementByName("gender");
var i;
for (i = 0; i < c.length; ++i) {
if (c[i].checked)
document.getElementById("display1").innerHTML = c[i].value; //looping through radio buttons
}
var d = document.getElementByName("hobbies");
for (i = 0; i < d.length; ++i) {
if (d[i] checked)
ans = ans + d[i].value; //looping through checkboxes and adding to display in display 2 id.
}
document.getElementById("display2").innerHTML = ans;
var e = document.getElementByName("cities").value;
document.getElementById("display3").innerHTML = e;
}
<form name="myForm">
<fieldset>
<legend>Personal Details</legend>
Name:
<input type="text" id="fname" <br>Password:
<input type="password" name="password" id="passwords" />
<br>Gender:
<input type="radio" name="gender" />Male
<input type="radio" name="gender" />Female</input>
<br>Hobbies:
<input type="radio" name="hobbies" value="Reading" />Reading
<input type="radio" name="hobbies" value="Writing" />Writing</input>
<br>City:
<select name="cities" />
<option>Surat</option>
<option>Ahmedabad</option>
<option>Rajkot</option>
<option>Vadodra</option>
</select>
<br>Image:
<input type="file" accept="image/*" value="image" style="margin:0px 10px 10px 100px; margin:absolute;" />
</form>
<br>
<input type="Submit" value="Submit" onSubmit="validateform(myForm);">
</fieldset>
<p id="display"></p>//display the values submitted within the html page
<p id="display1"></p>
<p id="display2"></p>
<p id="display3"></p>
- getElementsByName -复数,当访问第一个时,使用[0]like
document.getElementsByName("cities")[0].value
- 在
d[i].checked
中缺少一个点 - 将
onSubmit="validateform(myForm);"
移动到表单标签,并执行onSubmit="return validateForm(this);"
并添加返回false; - 事件处理程序中validateForm拼写错误(小写f)
- y失踪
- 未定义
function validateForm(myForm) {
var a = document.getElementById("fname").value;
document.getElementById("display").innerHTML = a;
var b = document.getElementsByName("passwords").value;
document.getElementById("display1").innerHTML = a;
var c = document.getElementsByName("gender");
var i, ans;
for (i = 0; i < c.length; ++i) {
if (c[i].checked)
document.getElementById("display1").innerHTML = c[i].value; //looping through radio buttons
}
var d = document.getElementsByName("hobbies");
for (i = 0; i < d.length; ++i) {
if (d[i].checked)
ans = ans + d[i].value; //looping through checkboxes and adding to display in display 2 id.
}
document.getElementById("display2").innerHTML = ans;
var e = document.getElementsByName("cities")[0].value;
document.getElementById("display3").innerHTML = e;
return false; // normally when error but here to stay on page
}
<form name="myForm" onSubmit="return validateForm(this);">
<fieldset>
<legend>Personal Details</legend>
Name:
<input type="text" id="fname" <br>Password:
<input type="password" name="password" id="passwords" />
<br>Gender:
<input type="radio" name="gender" />Male
<input type="radio" name="gender" />Female</input>
<br>Hobbies:
<input type="radio" name="hobbies" value="Reading" />Reading
<input type="radio" name="hobbies" value="Writing" />Writing</input>
<br>City:
<select name="cities" />
<option>Surat</option>
<option>Ahmedabad</option>
<option>Rajkot</option>
<option>Vadodra</option>
</select>
<br>Image:
<input type="file" accept="image/*" value="image" style="margin:0px 10px 10px 100px; margin:absolute;" />
</form>
<br>
<input type="Submit" value="Submit">
</fieldset>
<p id="display"></p><!-- display the values submitted within the html page -->
<p id="display1"></p>
<p id="display2"></p>
<p id="display3"></p>
相关文章:
- 从表单中获取用户输入执行计算(操作顺序)并输出回该表单
- 在模板中为Django表单分离媒体类对象的JS和CSS列表输出
- JQuery Script在表单提交后反转输出
- 为多个表单动态指定输出ajax成功结果的位置
- PHP表单输出保存在jquery的Excel工作表中
- 输出 html 表单数据
- 在表单中验证年龄但没有得到输出,不确定什么是不正确的
- 如何提交从第一个输出生成的第二个 AJAX 表单
- 如何通过隐藏表单在同一页面中显示表单输出
- 如何在同一窗口中显示表单输出并隐藏表单
- 表单提交未显示 JavaScript 输出
- 如何编辑我的 js,以便在输出输出之前清除表单
- 将显示与位置绝对输出移动的表单放入移动模式引导按钮中
- 通过 PHP 文件查询的表单条目和使用 JQuery AJAX 输出 PHP 文件的结果
- 表单提交时的 HTML 输出更新
- JS输出表单值接收到'undefined'在控制台
- JQuery“greying"输出表单中的文本字段
- 输出表单提交成功到页面,而不是重定向
- html页面内的输出表单
- 在同一页面上输出表单的内容以供公共查看