Laurie Harper wrote:
Catherine wrote:
3. <html:button property="submitAction" value="Add Property" onclick="javascript:checkProp()"> This is my real problem. I have a single selection dropdown menu which contains the allowed properties of the object. When user selects a property and clicks the Add Property button, I call checkProp() to check if it already added to the object. If yes, I alert user and don't submit form; if no, I call form.submit(). I found that submitAction="" if the form is submitted this way. I tried to do form.submitAction.value = "Add Property" before submit(), but that didn't help. How can I pass that value?


If you define an onclick event handler then, as far as I understand it, clicking the button will execute the event handler first and then submit the form second *if* the event handler returns true. So, if your checkProp() function returns true the form would be submitted as if you hadn't had an onclick handler; if it returns false, the form will not be submitted.

Almost :)

Note that an <input type="button"> (html:button> is different from an <input type="submit"> (html:submit). The button won't submit the form at all unless you write script to call form.submit(), it's just a button with no inherent functionality, as far as for form goes.

What you'd want to do is hook the onSubmit event of an actual submit button. There, you can call your validation code and as you say, return true to allow the form submission to go through, false to abort it.

I *think* the problem you are seeing Catherine, and I'm saying this from memory so I may not have it quite right, is that button values aren't submitted with the form unless it was an actual submit button. So, you would have to have a hidden form field named submitAction that you populate via script if the form isn't being submitted with an actual submit button.

For case 2, you're specifying the URL to load in the Javascript so you're not submitting the form. Therefore your form properties aren't included in the request. I'm not sure how you get the onclick handler to submit the form as if the handler weren't there, my Javascript fu isn't that good yet ;-)

That's correct, in case 2 the form isn't being submitted, so no parameters are sent. Basically, there is two mechanisms by which the form can get submitted: (a) the user clicks a submit button, or (b) some script calls submit() on the form. In the case of (a), you can hook the onsubmit event and call some function, and as Laurie said, return true to allow the form to be submitted, or false to stop it. In the case of (b), you hook the onclick event of a plain old button and you take on complete responsibility for submitting the form, it will never happen automatically in that case. In both cases it might be easier to have some script set a hidden field with the appropriate submitAction value, that way you have complete control over it.

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to