function validate(){
var username = document.getElementByProperty("userName").value;
var password = document.getElementByProperty("passWord").value;
if((username == null ||username =='') || (password == null||password=='')){
x=document.getElementById("error");
x.innerHTML = "Username or Password Cannot Be Blank";
else{
document.getElementById("loginform").submit();
}
<form id="loginform" action="login.do" method="post">
UserName:<html:text property="userName"></html:text>
PassWord:<html:password property="passWord"></html:password>
<html:button onclick="validate()"></html:button>
</form>
上面的代碼不工作,我無法獲得在文本框用於驗證的值......請幫我在這個問題上...使用struts html標記時,如何使用屬性屬性獲取文本框的值?有沒有其他的方式來獲得價值?
感謝您解決Mr.Reddy ...但是,Struts-html標籤沒有'id'屬性,這就是爲什麼我要求從property屬性獲取值。 – Rajaah
我猜Struts有styleId而不是「id」。更新我的回答 – Reddy
是的,對。但是,我必須知道兩者是相同的? – Rajaah