cancel
Showing results for 
Search instead for 
Did you mean: 

input field validation using JSP in HTMLB

former_member184111
Active Contributor
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

raja_thangamani
Active Contributor
0 Kudos

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

Answers (1)

Answers (1)

raja_thangamani
Active Contributor
0 Kudos

Replace "javascript error message here" with alert meesage. This editor is not allowing me to post Javascript code.

Raja T

former_member184111
Active Contributor
0 Kudos

Hi Raja,

I tried with your code but when i ry to execute the application there are two input fields displayed along with the whole JSP code ie from the script start till closing tag.

Thanks for the reply.

Message was edited by:

Anubhav Jain

former_member184111
Active Contributor
0 Kudos

The code is working perfectly..after minor alterations.

Thanks a ton .

Regards,

Anubhav.