简体   繁体   中英

Text Boxes Validations in Jsp

In my Jsp I have two text boxes txt1 and txt2

How can I validate these two text boxes ( txtboxes won't be same...)?

(I need an alert "Both the places are same")

Here is the code:

  <asp:TextBox runat="server" ID="txt1"></asp:TextBox>

        <asp:TextBox runat="server" ID="txt2"></asp:TextBox>

I would suggest you add a cssClass to them. So you have easier time selecting them. Here is an example:

Mark up

<asp:TextBox CssClass="compare" runat="server" ID="txt1">test</asp:TextBox>    
<asp:TextBox  CssClass="compare"  runat="server" ID="txt2">test</asp:TextBox>

Javascript

var elements = $('.compare');
if (elements.eq(0).html() === elements.eq(1).html()){
   //do stuff
}

Fiddle Demo

Remember this only does client side validation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM