cancel
Showing results for 
Search instead for 
Did you mean: 

Submitting HTMLB form using JavaScript

Former Member
0 Kudos

Hi all,

Does anyone know how to submit an HTMLB form, using JavaScript? I want to check the form, through JavaScript, and send a confirmation to the user. If the user clicks OK in the JavaScript confirmation, I want the onClick method to run (In a sense, if the user clicks OK on the confirmation, I want the form to submit). Otherwise, if the user clicks Cancel on the confirmation, I want the form to clear.

Here is an example of what I am trying to do:

<script language="JavaScript">

function checkForm() {

var msg = "Are you ready to submit the form?";

var c = confirm(msg);

if (c) {

//submit the form

//I get an Object Expected error on this line.

htmlbEL(this,2,'btnSubmit:submitForm')

}

else{

//clear the form

clearForm();

}

}

</script>

...

<hbj:button

id="btnSubmit"

text="Submit"

onClientClick="checkForm()"

design="STANDARD"

jsObjectNeeded="true"

/>

Thanks in advance for the help!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hmmmm. When I implement the line:

buttonid = myContext.getParamIdForComponent(btnSubmit);

I get a runtime error saying that the variable btnSubmit does not exist.

Also, the code in this thread looks to actually be clicking the button. I cannot add the onClick parameter to the button component, because I do not want the Java method to execute everytime the button is clicked. Instead, I want the Java execution method, which would be the value of the onClick parameter, to be called from the JavaScript, when the user confirms the input by clicking OK on the confirmation box.

Any ideas?

MartyMcCormick
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Alexa,

You can add both the onClientClick and onClick events to your button. When the onClientClick submits to your javascript function, you can evaluate your form as you describe. Then if the user clicks OK, you return true to the Javascript function to continue onto the Java onClick event, if they click Cancel, you return false and the htmlb form will not submit even with the onClick event being declared on the button.

For example, I evaluate an htmlb field here and if the field is null I cancel form submission:

function CheckForm() {
    var funcName = htmlb_formid+"_getHtmlbElementId";
    func = window[funcName]; 
    var inputfield = eval(func("if_urlText"));


    if (inputfield.getValue() == null) {
    	alert("You must complete all form fields!");
    	htmlbevent.cancelSubmit=true;
    	return false;
    }
   else
   {
	return true;	
   }
}

Hope this helps,

Marty

Answers (2)

Answers (2)

Former Member
0 Kudos

Thank you, Marty!

Former Member
0 Kudos

Hi Alexa,

Take a look at my answer for following forum post.