在使用struts html标记时,如何使用属性属性获取文本框的值?还有其他方法来得到这个值吗?

时间:2022-05-14 20:34:59
    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>

the above code is not working and I am unable to get the values in textbox for validation... Please help me out in this issue...

上面的代码不起作用,我无法在文本框中获取验证的值…请帮我解决这个问题……

2 个解决方案

#1


3  

function validate(){
    var username = document.getElementById("userName").value;
    var password = document.getElementById("passWord").value;
}


<form id="loginform" action="login.do" method="post">
    UserName:<html:text property="userName" styleId="userName"></html:text>
    PassWord:<html:password property="passWord" styleId="passWord"></html:password>
    <html:button onclick="validate()"></html:button>
</form>

#2


0  

Before reading next line, please install good web inspector. e.g.

在阅读下一行之前,请安装好网络检查器。如。

  • Firebug in Firefox
  • Firefox中的Firebug
  • Web Inspector in Chrome
  • 网络督察铬
  • IE Web Inspector
  • 即网络督察
  • and inspect the source

    并检查源

    Or you can view the source.

    或者你可以查看源代码。

       1. document.getElementsByName("userName")[0].value;
       2. document.getElementById("userName").value;
       3. document.forms["loginform"]["userName"].value
    

    #1


    3  

    function validate(){
        var username = document.getElementById("userName").value;
        var password = document.getElementById("passWord").value;
    }
    
    
    <form id="loginform" action="login.do" method="post">
        UserName:<html:text property="userName" styleId="userName"></html:text>
        PassWord:<html:password property="passWord" styleId="passWord"></html:password>
        <html:button onclick="validate()"></html:button>
    </form>
    

    #2


    0  

    Before reading next line, please install good web inspector. e.g.

    在阅读下一行之前,请安装好网络检查器。如。

  • Firebug in Firefox
  • Firefox中的Firebug
  • Web Inspector in Chrome
  • 网络督察铬
  • IE Web Inspector
  • 即网络督察
  • and inspect the source

    并检查源

    Or you can view the source.

    或者你可以查看源代码。

       1. document.getElementsByName("userName")[0].value;
       2. document.getElementById("userName").value;
       3. document.forms["loginform"]["userName"].value