Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

input field validation using JSP in HTMLB

Hi All,

How can we validate an input field in a form in BSP page.

Like: There are two input fields in my form.I want the user to enter value in any one and only one of the fields.If the value is entered in both fields or none of the fields the user should get a popup and form must not be submited.

Shall i use the onClientClick attribute of Button element or doValidate attribute of Inputfield element or validationScript attribute of From element?

Please help.

Thanks a lot,

Anubhav.

replied

Here you go:

<%@page language="abap" %>
<%@extension name="htmlb" prefix="htmlb" %>
<htmlb:content design="design2003" >
  <htmlb:page title=" " >
    <htmlb:form id="form1" >
      < script t-ype = "text/javascript" >     "Remove "-" between t & ype in type

      function checkInput()
      {

       var field1 = document.form1.field1.value;
       var field2 = document.form1.field2.value;

var error = "";

if(field1 != "" && field2 != "")
          { error = "X";
              javascript error message here          }

if(field1 == "" && field2 ==  "")
          { error = "X";
                            javascript error message here
          }

if(error == "")
          {
          htmlbSL(this,2,'mybutton:Submit');
          }
      }

      < / script >

          <htmlb:textView text      = "Hello World!"
                          textColor = "RED"
                          design    = "HEADER1"
                          align     = "CENTER" />
          <htmlb:inputField id        = "field1"
                            value     = "<%= var1 %>"
                            type      = "integer"
                            alignment = "CENTER" />

          <htmlb:inputField id        = "field2"
                            value     = "<%= var2 %>"
                            type      = "integer"
                            alignment = "CENTER" />

          <htmlb:button id            = "mybutton"
                        text          = "Press Me"
                        onClientClick = "javascript:checkInput();" />
    </htmlb:form>
  </htmlb:page>
</htmlb:content>

Raja T

Message was edited by:

Raja Thangamani

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question