cancel
Showing results for 
Search instead for 
Did you mean: 

Client side eventing with HTMLB

Former Member
0 Kudos

Hi All,

I am trying to access the HTMLB elements from jsp page to java script and failed to handle an event.

My requirement is, i have a form designed in First.jsp which is having 2 input fileds and both are mandatory. I want to display a msg to the user if he try to skip those 2 input fileds without value.

This i tried with dynpage it is working but i want to have with a JSP page, ie., all the presentation is in jsp file. so, how can i access those 2 input fileds in java scipt function?

If anybopdy is having an idea or a sample code please share here.

Thanks in advance,

Regards,

sireesha.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi sirresha,

You can try something like this.

<script language="Javascript">

function checkinput(){

var funcName = htmlb_formid+"_getHtmlbElementId";

func = window[funcName];

var inputfield1 = eval(func("inputfield1"));

var inputfield2 = eval(func("inputfield2"));

var input1 = inputfield1.getValue();

var input2 = inputfield2.getValue();

if (input1==null && input2==null)

alert("Enter mandatory fields");

}

</script>

In both the inputfields, set jsObjectNeeded="true".

For more info, refer to

Getting the InputField object in JavaScript:

http://help.sap.com/saphelp_erp2005/helpdata/en/43/067941a51a1a09e10000000a155106/frameset.htm

Hope this helps.

Regards,

Harini S

Former Member
0 Kudos

Hi Harini,

Thanks for your reply.I tried the same code but it is not showing the alert, i couldn't find where exactly the problem is!

Here i am putting my code please go through it and help me.

JSP file:

<%@ taglib uri="tagLib" prefix="hbj" %>

<%@ page import="com.sapportals.htmlb.enum.EventTrigger,com.sapportals.htmlb.event.Event" %>

<hbj:content id="myContext" >

<hbj:page title="PageTitle">

<script language="Javascript">

function checkinput(){

var funcName = htmlb_formid+"_getHtmlbElementId";

func = window[funcName];

var inputfield1 = eval(func("inf1"));

var input1 = inputfield1.getValue();

if (input1==null)

alert("Enter mandatory fields");

}

</script>

<hbj:form>

<hbj:textView id="tv1" text="Name"/>

<hbj:inputField id="inf1"

type="String"

required="true">

<% inf1.setJsObjectNeeded(true);

inf1.setClientEvent(EventTrigger.ON_BLUR, "checkinput()"); %>

</hbj:inputField>

<br>

<hbj:textView id="tv2" text="City"/>

<hbj:inputField id="inf2" type="String"/>

<hbj:button id="b1" text ="submit" onClick="onSubmitclicked"/>

</hbj:form>

</hbj:page>

</hbj:content>

Regards,

sireesha.

Former Member
0 Kudos

Hi sireesha,

Just saw the code. The value should be compared to "" instead of null. Sorry I have given the above code as null. Try this. This will definitely work.

<%@ taglib uri="tagLib" prefix="hbj" %>

<%@ page import="com.sapportals.htmlb.enum.EventTrigger,com.sapportals.htmlb.event.Event" %>

<hbj:content id="myContext" >

<hbj:page title="PageTitle">

<script language="Javascript">

function checkinput(){

var funcName = htmlb_formid+"_getHtmlbElementId";

func = window[funcName];

var inputfield1 = eval(func("inf1"));

var input1 = inputfield1.getValue();

if (input1==""){

alert("Enter mandatory fields");

}

}

</script>

<hbj:form>

<hbj:textView id="tv1" text="Name"/>

<hbj:inputField id="inf1"

type="String"

required="true"

jsObjectNeeded="true">

<% inf1.setClientEvent(EventTrigger.ON_BLUR, "checkinput()"); %>

</hbj:inputField>

<br>

<hbj:textView id="tv2" text="City"/>

<hbj:inputField id="inf2" type="String"/>

<hbj:button id="b1" text ="submit" onClick="onSubmitclicked"/>

</hbj:form>

</hbj:page>

</hbj:content>

Regards,

Harini S

Former Member
0 Kudos

Hi Harini,

That is working fine.

Thank you so much and i just want to give you full points but i couldn't since i forgot to mark the forum as a question. if is there any other way to give u points, i'll definitely give u..sorry for that.

thanks for your help.

Regards,

sireesha.

Former Member
0 Kudos

Hi sireesha,

Happy that u got it working. May be u can open a new thread and mark as a question. I will reply in that.

Regards,

Harini S

-


Thank you for the points

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Sireesha

You can do this using onClientClick event.

<b>onClick</b> - Defines the event handling method that will be processed when the user clicks on the enabled button.

<b>onClientClick</b> - Defines the JavaScript fragment that is executed when the user clicks on the button.The 'onClientClick' event is useful to preprocess the form and only send the form to client if the preprocessing was successful (e.g. date validation, valid number format etc.) to save client/server interaction.

Check out this link for details:

http://help.sap.com/saphelp_nw2004s/helpdata/en/f1/9a0e41a346ef6fe10000000a1550b0/content.htm

http://help.sap.com/saphelp_nw2004s/helpdata/en/43/067941a51a1a09e10000000a155106/frameset.htm (for javascript api)

Regards

Yoga

Former Member
0 Kudos

hi ,

Check this documentation on Javascript APIs <a href="http://help.sap.com/saphelp_nw2004s/helpdata/en/43/067941a51a1a09e10000000a155106/content.htm">JavaScript API</a>.

Regards,

Ganesh N