on 05-23-2005 2:13 PM
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!
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
Thank you, Marty!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
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.