18. april 2006 - 13:19Der er
6 kommentarer og 1 løsning
Submit buttons with same name in one form?
Hello!
I got a form with 2 submit-buttons with the same name. Might sound stupid but it would be great if this approach is ok. How ever the problem is how to evaluate wich version of the submit button that got pressed on the client side.
On the server side it is easy to see which button that got pressed but how do I do it on the client???
What about validating on each submitbutton's click-event rather than validating on the form. This way you will know which button triggered the submit (by sending a reference to the button as a parameter to the validating function). Something like this:
Maybe this is a solution. I use Struts as a framwork for validation. In struts it looks like they call the automatically genreated validations-functions with like: <html:form action="/ProductFormAction" method="post" onsubmit="return validateProductForm(this);">
Perhaps I could do a check before onsubmit.
Do you know how I do not submit if something is not correct?? For eg:
Would the case "submitButton.value == "mysubmit 2" submit the form and call onsubmit? And would the case "submitButton.value == "mysubmit 1" not submit the form?
Unfortunately I don't know Struts hence I can't supply specific help on how to do things with that framework.
I do know however that you have to return the return-value from your validating function in the inline onclick-event of the tag for the returnvalue to have any effect in cancelling the eventpropagation (i.e. not posting the form even though you push the submit button). This would render your form something like this:
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.