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.

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

Similar Messages

  • Accessing input field from the JSP in dynpage

    HI all,
          I am trying to access the input field of the jsp page in my JSPDynpage but it is always return null.My Input is a normal HTML element not a HTMLB element
    JSP File :
         <hbj:content id="myContext" >
      <hbj:page title="PageTitle">
      <hbj:form id="myFormId" >
         <div class="content">
            <table cellpadding="2" cellspacing="2">
                        <tr>
                               <td>
                                  <label for="name"><strong>UserName:</strong></label><span id="info_name">(This field is required)</span><br />                           
                                     <input name="name" id="name" size="10" maxlength="10" type="text" />
                               </td>
                        </tr>
                        <tr>
                             <td>
                                  <label for="email"><strong>EmailID:</strong></label><span id="info_email">(This field is required)</span><br />                           
                                     <input name="email" id="email" size="20" maxlength="20" type="text" /></td>
                        </tr>\
    </Table>
    JSPDynpage:
           InputField myInputField = (InputField) getComponentByName("name");
         if (myInputField != null) {
          name = myInputField.getValueAsDataType().toString();
                   InputField myInputField1 = (InputField) getComponentByName("email");
         if (myInputField1 != null) {
          name = myInputField1.getValueAsDataType().toString();
    In both the cases myInputField and myInputField1 are null . My Question is what should be the parameter that i need to pass for getComponentByName method.
    Regards,
    Raj.

    hi,
    The way you are trying to get the input field value works good with hbj type elements.
    either you change your input field to an hbj one or use java script inside your jsp page to catch the value
    like
    for HTML:
    [HTML Input Field|http://www.w3schools.com/HTMLDOM/met_doc_getelementbyid.asp]
    and for HTMLB
    refer this link:
    [SAP HTMLB GuideLines|http://www.sapdesignguild.org/resources/htmlb_guidance/index.html]
    Regards,
    Srinu

  • LOV for an unbound input field in ADF-JSP

    Hi i have a web app using ADF BC, struts , JSP.
    Jdev - 10.1.2
    JHS - 10.1.2
    I have a text field <input type="text" value="solution">
    I need to populate this UNBOUND input field with a value from an LOV which pops up in a separate window.
    I need help right from the beginning... which i guess wud be to create a VO for it.. i have never done it earlier so any help wud be useful.

    Hi,
    try
    <BODY onload="document.DataForm.EmployeeId.focus()">
    where EmployeeId needs to be substituted by the name used in the textfield property
    <html:text property="EmployeeId"/>
    If this was Empno then the example would be
    <html:text property="Empno"/>
    and
    <BODY onload="document.DataForm.Empno.focus()">
    Frank

  • Input field validation in a Table based on the value of other column

    Hi all
    I have a table with 2 columns. column1 is of text view and  column2 is Input field.
    The user should not be allowed to enter a value  in the column2 ( input field) greater than the value populated in column1(textview).
    So for Eg; if the column1 is populated with value 100, The user should not be able to enter a number greater than 100 in the column2  input field.
    Please let me how this can be achieved.
    I appreciate the help.
    Thanks

    Hi,
    Let me make sure u r working with table control.
    First u have to create a event(VALIDATE) to do the validation.
    Inside the event,
    1. First get the current index where user has pointed the curson
    2. Once u get the index read the internal table with index value.
    3. Now u can compare the col1 and col2 values and populate the error message.
    1. DATA : lo_elt TYPE REF TO if_wd_context_element,
                   l_index type i.
    lo_elt = wdevent->get_context_element( name = 'CONTEXT_ELEMENT' ).
         CALL METHOD LO_ELT->GET_INDEX( RECEIVING  MY_INDEX = l_index.
    above code should be written inside the event.
    Thanks,

  • Change input fields of used component

    Hello,
    I am creating a web dynpro and don't have a lot of experience so I hope you can help me.
    I am using the component /PLMU/WDC_SEA_QS_CRIT_DO which contains an input field OBJECT_TYPE.
    How can I enable this field in my web-dynpro?
    Thank you very much.
    Best regards,
    Daisy Heremans

    Hi
    If you can't set the interface property of node in enhancement then there is another way.
    Keep the node as it is.
    Keep some static class attribute for enable \ disable.
    Set this static class attribute in your component and use this attribute in used component ( any of post\ pre overwrite methods ) to set this attribute value to the attribute which is bound to UI element enabled property.
    @ thomas: any inputs from your side, can we achieve this in any other way apart from enhancement through personalization \ component configuratio etc ?
    Regards
    Manas Dua

  • Input field validation in web dynpro abap

    Hi....i have a input field in a view, which is bound with dictionary object of char type ,through context.for this input field, i have to allow the end users to enter the numeric and float values only,but in my condition it accepting everything and returns runtime error.for this how to validate inputs other than numerics.
    Thanks & regards,
    pavan maganti.

      DATA lo_nd_itab2 TYPE REF TO if_wd_context_node.
      DATA lo_el_itab2 TYPE REF TO if_wd_context_element.
      DATA ls_itab2 TYPE wd_this->element_itab2.
      DATA lv_non_numeric TYPE wd_this->element_itab2-non_numeric.
    *     get message manager
      DATA lo_api_controller     TYPE REF TO if_wd_controller.
      DATA lo_message_manager    TYPE REF TO if_wd_message_manager.
    * navigate from <CONTEXT> to <ITAB2> via lead selection
      lo_nd_itab2 = wd_context->get_child_node( name = wd_this->wdctx_itab2 ).
    * get element via lead selection
      lo_el_itab2 = lo_nd_itab2->get_element( ).
    * get single attribute
      lo_el_itab2->get_attribute(
        EXPORTING
          name =  `NON_NUMERIC`
        IMPORTING
          value = lv_non_numeric ).
      IF lv_non_numeric CO '1234567890'.
        lo_api_controller ?= wd_this->wd_get_api( ).
        CALL METHOD lo_api_controller->get_message_manager
          RECEIVING
            message_manager = lo_message_manager.
    *     report message
        CALL METHOD lo_message_manager->report_success
          EXPORTING
            message_text = 'All numeric'.
      ELSE.
        lo_api_controller ?= wd_this->wd_get_api( ).
        CALL METHOD lo_api_controller->get_message_manager
          RECEIVING
            message_manager = lo_message_manager.
    * report message
        CALL METHOD lo_message_manager->report_warning
          EXPORTING
            message_text = 'Contains characters'.
      ENDIF.

  • Field validation using distributed form's "Submit Form" built-in function

    Hello,
    I am hoping someone can help me out with a small problem I'm having. I have a hidden field on a form which is the total of other numeric values on the form with code in place so that if the number doesn't equal what it should, the alert box is displayed. The problem is that it's a distributed form and even though the message is displayed, if you hit submit (Built-in Submit Form) button form on a second attempt, it submits anyway. So the question is, how do I change the built-in API submit button code to catch the error? Because it's a distributed form, am I dealing with global variables vs. form level? I've tried using the "event.rc = false" at the form level to no avail. I can't seem to locate the built-in "submit form" code so that I can change that to make this APP work. Or is there a better way to do this. My validation code is below and I would greatly appreciate anyone's help.
    Thanks,
    Tom
    // JScript source code if (this.getField("RankGame1").value > 0 &&     this.getField("RankGame2").value > 0 &&     this.getField("RankGame3").value > 0 &&     this.getField("RankGame4").value > 0 &&     this.getField("RankGame5").value > 0 &&     this.getField("RankGame6").value > 0 &&     this.getField("RankGame7").value > 0 &&     this.getField("RankGame8").value > 0 &&     this.getField("RankGame9").value > 0 &&     this.getField("RankGame10").value > 0 &&     this.getField("RankGame11").value > 0 &&     this.getField("RankGame12").value > 0 &&     this.getField("RankGame13").value > 0 &&     this.getField("RankGame14").value > 0 &&     this.getField("RankGame15").value > 0 &&     this.getField("RankGame16").value > 0)     {       if (this.getField("RankGameTotal").value == 136) {         } else {         event.rc = false;         app.alert("Please check your confidence points. They should add up to 136, but are adding up to " + this.getFiel         ("RankGameTotal").value + ".");        }     } else { }

    try67,
    Thanks for your reply. When you say to "remove the Submit action, and submit the form yourself inside your code" are you refering to the
    distributed forms "Submit Form" button displayed on the purple tool bar of the distributed form? And if so, could you please let me know how I can do that? I've
    looked into that and haven't found an answer. Doing that would solve my problem of having my own submit code acting correctly and the
    distributed forms "Submit form" code not having any idea about my forms desired field value.
    Thanks again,
    Tom

  • Table Input field validation

    Hi Experts
    I have an OIF Application in which I have an Input enabled table and it is mandatory to enter the date range fields. When the user clicks 'SAVE', I have to validate if the start and end dates are entered in each record, and give an error message if blank. I wanted to know if I have to loop through each record and validate manually or if there is a better way?
    Thanks
    Neo

    Hello Neo,
    you can use the utility method CL_WD_DYNAMIC_TOOL=>CHECK_MANDATORY_ATTR_ON_VIEW to check for the mandatory attributes.
    For this you need to set the STATE property of the inputfield (in the table column) to REQUIRED.
    BR, Saravanan

  • Edit Field Validation - Use of the native string.find() Lua Function

    Hi,
    I have an edit field in which I want to be validated immediately upon change.  I ONLY want to accept alphanumeric characters (a-z and 0-9).  I have tried this many ways, but have failed to get it exactly as I want it.  First I tried Sample Code A, but that line of code fails because combination strings that contain the alphanumeric characters and a special character like the pound sign (#), will validate (Example: "hello1#").  I tried Sample Code B, but that isn't 100% what I want because if you were to add a character that isn't available on the keyboard, such as the copyright symbol or the trademak symbol.  Can someone help me, please?  Thank you.
    Sample Code A:
    interface:edit_field {
                                value = bind { key = 'new_table', object = properties },
                                fill_horizontal = 1,
                                immediate = true,
                                validate = function (interface, value)
                                  if string.find(value, "[a-z%d]")  then
                                    return true, value, "good"
                                else
                                        return false, value, "failed"
                                    end
                                end
    Sample Code B:
    interface:edit_field {
                                value = bind { key = 'new_table', object = properties },
                                fill_horizontal = 1,
                                immediate = true,
                                validate = function (interface, value)
                                    if string.find(value, "[~!@#$%^&*()_+`-={}|\%[%]:\";'<>?,./]")  then
                                    return false, value, "failed"
                                else
                                        return true, value, "good"
                                    end
                                end

    wallanceM wrote:
    Hi,
    I have an edit field in which I want to be validated immediately upon change.  I ONLY want to accept alphanumeric characters (a-z and 0-9).
    Sample Code A:
    interface:edit_field {
                                value = bind { key = 'new_table', object = properties },
                                fill_horizontal = 1,
                                immediate = true,
                                validate = function (interface, value)
                                  if string.find(value, "[a-z%d]")  then
                                    return true, value, "good"
    Hi,
    Sample Code A seems the best approach to use.  Trying to detect unwanted characters would be error prone.
    I noticed you are mixing character classes and ranges in your string.find pattern.  Have you tried using the following patterns instead?
                                  if string.find(value, "[a-z0-9]")  then
    or
                                  if string.find(value, "[%l%d]")  then
    Matt

  • Alv Input Field Validation

    Hi Experts,
    In my initial screen there are some search criteria based on which i ve to display the data by using ALV.
    And i ve hardcoded some value and the data are coming  in ALV . But my question is how can i validate the data which is enter by the user in the search field so that data can bedisplay based on the search criteria in the alv output.
    Regards,
    Satya

    Hi ,
    use OVS (object value selector) method there , it wll take input and according to that f4 will be displayed.
    OVS Component:
    https ://OVS Input Help
    http://help.sap.com/saphelp_erp2005/helpdata/en/30/d7fa41c915da6fe10000000a1550b0/content.htm
    Packages : WDR_TEST_OVS2,WDR_OVS,WDR_TEST_OVS
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/user-interface-technology/webdynpro/wd%20java/wdjava%20archive/web%20dynpro%20valuehelp%20using%20object%20value%20selector.pdf
    /people/shruti.rathour/blog/2008/05/05/ovs-help-in-web-dynpro-abap
    Regards,
    Muneesh Gitta.

  • How to make the server slide form validation using JSP?

    anyone knows how to do server-side form validation??
    Thanks in advanced

    try this way
         //create a validation java class in that class u create separate methods for validating
         for example if u want to validate that a particular text box should not be empty
         then u can try this way
         say like this
         class ServerValidation()
         boolean message=false;
         public static boolean isTextBoxEmpty(String value)
         if(value.length<1)
         System.out.println("Text box is empty");
         message=false
         else
         message=true
         return message
    now say u r having a html page in which there is a text box on submiting u call say validate.jsp
    in this jsp u write this way
    <%
    String message=request.getParameter("name of ur text box");
    boolean b=ServerValidation.isTextBoxEmpty(message)
    if(b)
    //valid is true do ur other activity
    else
    String messageToUser="Please Enter Some value"
    u can now display this message on jsp and create a back button
    %>
    hope its clear

  • Assigning html input value to a jsp variable

    I have the following problem: I need to assign the value of html <input> field to a jsp variable. This should be done without submittion of the form.
    <form name="main">
    <table>
    <tr>
    <td><input type="text" name="gantry" value="123"></td>
    </tr>
    <table>
    </form>
    Is there any way to access main.gantry.value from jsp and assign it to a variable? I tried
    <% prevGantry = main.gantry.value; %>
    but it didn't work, and the problem is not with parsong or initialisation. Please, can anyone help?
    Best regards, SoVa.

    No it can't be done. You are mixing up java with javascript.
    Java/JSP runs on the server end. Generates an HTML page and stops running.
    The page loads in the browser, and and can run javascript locally.
    The only way to run java code again is to go through the request/response process. ie submit a form, click a link, make an Ajax call...
    The only way to get a field from the screen into a java variable is via request.getParameter().

  • Search help for a Input Field........

    Hi,
      I'm fairly new to BSP and I would like to know how to attach Search Help to the Input Field in BSP application.
    Thanks
    NP.

    Hi nagendra
                        Search Help for input field Provide using attribute of input field is showHelp and onvaluehelp
                      This is providing the search help .

  • Javascript validation of input field in HTMLB in jsp

    Hi... i am using Javascript in HTMLB in JSP for input filed validations .
    According to the requirement , the Input Field should start with only "Alphanumeric values" .
    Can somebody please help me out in this.
    Regards
    Smita

    Hi,
    using java script can write like this
    function validate(str){return str.substr(0,1) == str.substr(0,1).toUpperCase();}
    Regards
    Supraja
    Edited by: Supraja Koganti on Nov 27, 2008 12:16 PM

  • How to validate the input field data in VC using RFC FM

    HI,
    Could any body please give me the solution for the following issue?
    When ever I enter a value in the input field of an iView, this value has to be validated from the backend BW system.  Is this validation is possible using RFC function module?
    If yes, please explain me.

    Hi Deepak,
    U can validate input fields using javascript.Write OnClientClick function for that submit button if ur using htmlb or onClick if u r using html.Refer the follows
    http://help.sap.com/saphelp_nw70/helpdata/en/03/900e41a346ef6fe10000000a1550b0/frameset.htm
    There are two ways to achieve ur task.
    1.By checking for all alphabets.in this u need check all the alphabetic characters one by one.Refer the following
    http://www.shiningstar.net/articles/articles/javascript/javascriptvalidations.asp?ID=ROLLA
    http://www.shiningstar.net/articles/articles/javascript/checkNumeric.asp?ID=AW
    2.By using regular expressions.its very easy and a single line code.here u need to specify single expression for whole alphabets.Refer this
    http://aspzone.com/blogs/john/articles/173.aspx
    Regards,
    Naren

Maybe you are looking for

  • How do you move music from one computer to another

    I have ripped my entire CD collection to an old laptop, basically turning it into a jukebox.  I would like to move the music to my new laptop as well.  I have tried to copy the music folder to an external hard drive and then copying it to the music f

  • R61 will not power on, no beeps or POST

    My R61 only blinks green power / amber battery for a second and will not turn on.  No beep, no POST. Recently the original battery in the R61 went from about 60% capacity to 3% capacity overnight.  Since I had purchased used, I suspected the generic

  • How can I order a spanish wireless keyboard?

    I want to order the wireless keyboard for my Ipad 2 but can't find the option to choose a spanish keyboard, does anybody knows the direct link or how can I do so? Thank you!

  • Oracle 11g R2 Edition feature

    Hi All, I am trying out the Oracle 11gR2 edition feature .Can any one please give me a hand on how to make a particular edition available to a set of users. I understand that one way is ALTER SESSION SET EDITION = <edition_name> but that applies to c

  • Servies agreement  header data

    Hi guru i am uploding servies agreement header data, for t-code me31k, while uploading data i got  an error in STEP -> CONVERT DATA . 1)syntax error in program /1CADMC/SAP_LSMW_CONV_00000066. 2)in include /1CADMC/SAP_LSMW_CONV_00000066. in line:27. F