开发者

Can I share data between forms on HTML pages? Or can submitting one form, submit another?

开发者 https://www.devze.com 2023-03-05 13:14 出处:网络
I wonder if anyone can advise? I have a JSP which contains two forms, both of which are mapped to the same servlet on the server.

I wonder if anyone can advise? I have a JSP which contains two forms, both of which are mapped to the same servlet on the server.

Everything seems fine although when I submit one form, a necessary piece of data entered on the other form is not being submitted at the same time.

The first form is used to add or delete the address of an RSS feed. As there may be several addresses on the page, a table is used to store them. Each cel开发者_开发问答l of the table contains a form like this for deletion:

<form action = "<c:url value = '/deleteRSSFeed?rssFeedURL=${rssFeedURL}' />" method = "post">                           
<input type = "image" src = "${imageFileURL}myApp_rightArrow.png" />                            
<input name = "writeWordcloud" type = "hidden" value = "true" />
</form>

And there is another form for adding a feed.

The situation is that upon submission of either of these forms, a wordcloud must be redrawn on the page. But the wordcloud's settings are contained in the other form.

As it not possible for me to merge the forms, can anyone tell me if I can share data betwen forms in HTML? Or better yet, is it possible to submit one form, and have this action submit the second form?

At this point, it is not practical for me to have the forms served by different servlets.

Thanks

Mr Morgan


By using Javascript (or better, jQuery), you can have hidden fields in one form get the other form's fields values before submitting.

Update

This fiddle shows the code you need: http://jsfiddle.net/MqsK8/1/


You should probably use a single form, and have the server-side script perform both actions.
Depending on your scenario, you may want to have two submit buttons for different tasks; the server can check which button was clicked.


It would if you can provide detail of what you are trying to do. You can use Javascript to add elements to DOM but again all of this will depend on your use-case.

0

精彩评论

暂无评论...
验证码 换一张
取 消