submitting multiple forms with one submit button - html

I have an application where in a signed in user searches a database and is displayed a table of results. These results are basically listings of events. I give the user then, the privilege to "keep" or "discard" any event (using radio buttons beside each event).
Now however, I wish to implement a functionality whereby, the user at the end can click just one "update" button and all changes are affected (since keeping one button for each record will be very user unfriendly). That is, I am looking equivalently to submit multiple forms with just one submit/update button.
Is this possible ?

You need to use javascript, I suggest you using JQuery. Using AJAX you need to submit each form - this way page will not be redirected once you submit a form!
Then, within each forms assign individual IDs for each form. Then, assign your submit button an id for example mySubmit. Up next, add following code:
$('#mySubmit').click(function(){
// submit form1 by ajax...
// submit form2 by ajax...
});
You may see jQuery's http://api.jquery.com/jQuery.post/ for further information on how to submit a form using ajax.

As long as all of the radio buttons and submit button are part of the same form, you don't need to worry about submitting multiple forms because there won't be any. You can have multiple submit buttons in a single form, you can give them different values to know which button was clicked.

If you don't want to use jQuery then use javascript to form a list of data separated by say ~ character and set this string to some hidden field and submit using document.formx.submit()
You will need to parse the string on server side to get the data in correct format.

Related

Multiple submit buttons in an HTML form with a MySQL Backend

I have multiple submit buttons in a form. How do I send all the information from the form to a MySQL backend just once? I know how to do it with just one submit button.
Additional information is that I have multiple submits to create a multiple step form and I want to go ahead with the multiple submit solution.
You would need to have multiple forms if creating this without using Javascript

Form should submit collected values to separate links

I have initially created a form with a formid="blah" method="GET" action="blah.com". The form collects certain attributes and passes it on to blah.com on submit. Suppose i include a drop down/ radio buttons upon selection the form's action should be changed, i.e should submit to either of three separate forms. Could anyone explain how form action works? could i call function in the action attribute or any other attribute?
The action attribute does not allow any script code.
However you can change the action value in the onchange event of your select inputs or via onsubmit of your form. Both of them allow you to use javascript code, which you can use to change the outcome of your form, depending on the input.
In case you use jQuery, you can easily get those with $('input#yourdropdownsname').val(). The same holds for your form to change the action value.
See this javascript - change form action based on selection? for a full code example.

save all options of struts select element

I would like to implement a dynamic select element using struts. I need to allow the user to add option elements to a select element on a page, then save all options when the form is submitted, not just the selected option. As a matter of fact, I do not even care about the selected option once submitted.
For instance, when a user enters a page, the select element is populated by a collection in the form bean. The user can then add, edit or remove options in the displayed select element (via jQuery, javascript). Then, the updated set of options are sent to the server when the user submits the form.
Here is where I am starting:
<html:select property="myList">
<html:options property="myList"/>
</html:select>
Is there a neat clean way to do this with the struts tags?
The struts tag doesn't have anything to do with the problem. All it can do is generate an select box containing options retrieved from the form bean. The problem is that an HTML select box only submits its selected option(s). That's what it's for.
If you want to submit all the options, make your select box multi-selection, and make sure that all the options are selected before submitting the form (using JavaScript, in the form submit event handler).
Or if you want to keep the select box as it is, create a hidden field for every option of the select box before the form is submitted (still using JavaScript, in the form submit event handler).

submit button submits wrong form

I have two forms, a login form and a register form on the same page and each has its own submit button. If I fill in bad data and click on submit button on register form, I get the form back with errors ( expected). If I now enter sign in details on signin form and click on signin form's submit button, the register form gets submitted.
This is strange behaviour. I am not sure where to start search for this. I am using firefox to test this.
Thanks
Well, you will need to debug it step by step.
Check your form nesting and follow good structure, make sure both form are not overlapping with each other or not being closed properly.
Give you form a proper ID and NAME. Be careful when two forms have the same name From Name Attr.
Based on your structure and your question, make sure you have a different submit buttons for each form and that button is placed within the form nesting.
Same as for the forms, give your submit button a proper unique ID and NAME .
Choose whether you want to submit by your using submit in html, or having JS to submit the form for you JS submit form.
If you are using HTML5, you can separate the button from the FORM. They can run separately. Means dynamic association between the form and it's submit button by having submit button placed anywhere and can submit a form located in different place. Check Association of Controls and Forms & HTML5′s New “form” Attribute.
Please post some code in order for us to have a better understanding of your issue.
Good luck.

how to send data from two forms in a jsp page when u click on submit in one form

In my project i have a scenario like this if i click submit in a jsp which has two forms i have send data from two forms to destination,how can i do that,Please help me out.
If you mean that you want to send the data from the two forms in the same request, that is not possible.
You would have to copy the data, either from one form to the other, or from both forms into a new form.
You can put hidden fields in a form for the values that you need to copy to it.
The only way i think you can do this is completely bypassing the FORM- mechanism. You could put an onclick() javascript event on the submit buttons which calls a javascript function you could call sendAll() or something.
In this function you could get all your formfields and values and then send an XMLHttpRequest (this is the basic of an ajax request) with all that values in it.
That is indeed complicated but it seems to me that this is the only way it could work.