[英]jQuery/Javascript - Get value of text input field, and display in div
[英]Get input field value and display it in a div using javascript
我在提交表单后尝试在div中显示输入字段值。但是我无法做到。
我做错了什么?
有人能帮助我吗?
function validate() { var a = document.forms["Form"]["uname"].value; var validation=true; if ((a == null || a == "")||(!a.match(/^([a-zA-Z]{2,30})$/))) { document.getElementById('uname').className = 'box'; document.getElementById('popup').innerHTML= document.getElementById('uname').value; validation=false; } else{ document.getElementById('uname').className = ''; } return validation; }
.box { border: 2px solid red; } #popup { width:25%; height:115px; background-color: red; margin-top:2% ; margin-left: 60%; color: black; }
<head> </head> <body> <form method="post" name="Form" onsubmit="return validate()" action="" id="form_id"> <label>NAME:</label> <input type="text" name="uname" id="uname" class="fields" > <button type="submit" name="submit">SUBMIT</button> <div id="popup"></div> </form> </body>
问题是if else条件。 内部html应该处于其他状态
if ((a == null || a == "")||(!a.match(/^([a-zA-Z]{2,30})$/))) {
document.getElementById('uname').className = 'box';
validation=false;
} else{
document.getElementById('uname').className = '';
document.getElementById('popup').innerHTML= document.getElementById('uname').value;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.