How to get textbox values
<form:form method="get" action="" onsubmit="return matchPassword();" id="myform" commandName="users">
<ul>
<li>
<form:label path="password" id="newPwd"><spring:message code="label.password"/></form:label>
<form:input path="password"/>
</li>
<li>
<form:label path="password" id="RePwd"><spring:message code="label.password"/></form:labe开发者_运维技巧l>
<form:input path="password"/>
</li>
<li>
<label> </label><input type="submit" class="btn" value="<spring:message code="label.adduser"/>"/>
</li>
</ul>
</form:form>
As given i have two input boxes for password. now i want to compare whether value of both the boxes are same using java script. How can i get values from these text boxes, Please suggest.
window.matchPassword = function(){
return document.getElementById('newPwd').value == document.getElementById('RePwd').value;
}
Just bashed this out - haven't tested it, but it should put you in the right direction.
var newPwd = document.getElementById('newPwd').value;
var RePwd = document.getElementById('RePwd').value;
if (newPwd != RePwd)
{
alert("Passwords Don't match");
}
You can use this:
var txt1 = document.getElementById('newPwd');
var firstPwd = txt1.value;
var txt2 = document.getElementById('RePwd');
var rePwd = txt2.value;
And then compare the two variables firstPwd
and rePwd
for equality:
if (firstPwd == rePwd)
// proceed
else
// notify error!
精彩评论