on 05-02-2006 8:06 AM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
94 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.