cancel
Showing results for 
Search instead for 
Did you mean: 

HTMLB/JSP - Javascript Submit

SidBhattacharya
Product and Topic Expert
Product and Topic Expert
0 Kudos

How do I submit an HTMLB form using javascript.

document.forms[formId].submit();

works and it seems to refresh the page after submit but it doesnt call the event that is triggered when the htmlb submit button is triggered(which is what i want to do actually).

I read a post which used this

htmlbSL(this,2,'SUBMITVALUES:SendButtonClicked')

but this too didn't work. error - 'Object not defined'

here is htmlb submit button definition

<hbj:button id="btn_update" text="Update" tooltip="Update Specification" onClientClick="validate()" onClick="SendButtonClicked" width="100" design="EMPHASIZED"/>

Any ideas?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Siddartha,

Add the following lienes to your<b> validate</b> function in your javascript. Paste it the way i am sending you. don't change anything.

var form = document.all(htmlb_formid);

form.submit();

SidBhattacharya
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Prakash,

While your code correctly works it has the same effect as

document.forms[formId].submit();

I do not want to submit the form from the validate() method but from a KeyEvent

document.onkeypress = function (evt) {
		if (!evt && window.event) {
			evt = window.event;
......
....
//Submit form here

}
}

Former Member
0 Kudos

Hi,

Sorry i totally misunderstood you. I thought the javascript was not working. Are you getting any errors in your original code. Have you defined event method in you java code.

SidBhattacharya
Product and Topic Expert
Product and Topic Expert
0 Kudos

no i am not getting any errors when i do a form.submit()

but the problem is that when the form submits to the dynpage it doesnt call any backend event, it goes to PBO directly.

so i guess there should be some way to trigger a backend event from javascript. the event that is triggered when i click the submit button is onSendButtonClicked and thats because the submit button is defined as

	<hbj:button id="btn_update" text="Update" tooltip="Update Specification" onClientClick="validate()" onClick="SendButtonClicked" width="100" design="EMPHASIZED"/>

if i want to "simulate" the click on submit button, how do i do that?

Some one mentioned in another post about this HTMLB method

htmlbSL(this,2,'SUBMITVALUES:SendButtonClicked')

which makes perfect sense since it should call the onSendButtonClicked event in the dynpage. For some reason this doesnt work for me.

Former Member
0 Kudos

Take a look at the following code. This is your solution except for <b>control + S</b> part.

PS: Thanks for the points in advance if it works out for you.

<%@ taglib uri="tagLib" prefix="hbj" %>
<%@ page import = "com.sapportals.htmlb.enum.EventTrigger" %>
<%
	String buttonid = "";

%>
<hbj:content 
	id="myContext">
	<hbj:document>
		<hbj:documentHead 
			title="test">
		</hbj:documentHead>
		<hbj:documentBody>
			<hbj:form 
				id="simpleForm">
				
				<hbj:inputField
           id="InputName"
           type="string"
           maxlength="100"
           value="Your name here"
           jsObjectNeeded="true">
                <%
                    InputName.setClientEvent(
							EventTrigger.ON_KEYDOWN,
							"Submit_Event()");
					%>
               </hbj:inputField>
               
				<hbj:button 
					id="SubButton" 
					text="Submit" 
					tooltip="Sends your info" 
					onClick="onClicked" 
					width="30px" 
					design="EMPHASIZED"
					jsObjectNeeded="true">
                  <%
                   buttonid = myContext.getParamIdForComponent(SubButton);
                  %>

				</hbj:button>
			</hbj:form>
		</hbj:documentBody>
	</hbj:document>
	<script 
				language="javascript">
				function Submit_Event() { 
				    var src= window.event.srcElement;
                    k = window.event.keyCode;
                    if (k == 13) {
                   // enter key pressed
                     document.all.<%=buttonid%>.click();
                     
                   }
               }
			</script>
</hbj:content>

Answers (0)