Patrik Krehák
Patrik Krehák

Reputation: 2683

Targeting button to form from other form

This one is possible to make with JavaScript, but I'm curious about pure HTML solution. What's my point of this question:

I have a form:

<form action...>
    <input type... />
    <label for...>...</label>
    and other elements for basic form...

    <button type="submit">Send</button>
    <button type="submit" target="hidden-form">Remove</button>
</form>

And somewhere else I have this another form:

<form id="hidden-form" action...>
    <input type="hidden"... />
</form>

So my point is, that pressing button "Remove" will post form #hidden-form. Is something like that possible? I tried that attribute target, but no help.

Upvotes: 1

Views: 45

Answers (2)

Jaqen H&#39;ghar
Jaqen H&#39;ghar

Reputation: 16814

You can use <button>'s form attribute:

<button type="submit" form="hidden-form">Remove</button>

<form id="hidden-form" action...>

Upvotes: 1

Gomzy
Gomzy

Reputation: 431

I think you want something like this, using jQuery it is possible try it:

$("#remove").click(function(){
	$('#hidden-form').submit();
});
<form action...>
    <input type... />
    <label for...>...</label>
    and other elements for basic form...

    <button type="submit">Send</button>
    <button type="submit" id="remove" onClick="document.forms['hidden-form'].submit();
">Remove</button>
</form>


<form id="hidden-form" action...>
    <input type="hidden"... />
</form>

Upvotes: 0

Related Questions