admin管理员组文章数量:1317915
I have a ad banner that has a form and this is used by 3rd party site owners that grab this code and have this banner on there site.
Since some sites that use this banner have a <form>
wrapping there entire site I have found that the banners form doesn't submit it rather submits the outer form.
Here is the code:
<form onSubmit="return alert('outer form submitted')">
<!-- only if i add this empty form it submits the inner -->
<form></form>
<!-- End Empty form -->
<!-- inner form -->
<form onSubmit="return alert('inner form submitted')" >
<input type="submit" />
</form>
<!--end inner form -->
</form>
As you can see only if I add a empty <form>
before the inner <form>
it alert (submits) the inner, otherwise it submits the outer.
What is the best way to code a banner ad for a site with a form?
I have a ad banner that has a form and this is used by 3rd party site owners that grab this code and have this banner on there site.
Since some sites that use this banner have a <form>
wrapping there entire site I have found that the banners form doesn't submit it rather submits the outer form.
Here is the code:
<form onSubmit="return alert('outer form submitted')">
<!-- only if i add this empty form it submits the inner -->
<form></form>
<!-- End Empty form -->
<!-- inner form -->
<form onSubmit="return alert('inner form submitted')" >
<input type="submit" />
</form>
<!--end inner form -->
</form>
As you can see only if I add a empty <form>
before the inner <form>
it alert (submits) the inner, otherwise it submits the outer.
What is the best way to code a banner ad for a site with a form?
Share Improve this question edited Feb 13, 2022 at 9:48 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jun 16, 2010 at 21:22 adardesignadardesign 35.8k15 gold badges66 silver badges86 bronze badges1 Answer
Reset to default 9Having a <form> inside a <form> is malformed HTML, and all bets are off how any browser/user-agent/javascript-engine/dom implementation is going to handle it. Expect wildly different or equal results between different visitors. Just don't have a <form> in a <form>. Period :)
Most likely scenario in your observed behavior: starting a <form> tag inside a form is probably 'discarded' as invalid, including any actions/events (but probably not <input>s), the first </form> closes the 'main' form.
本文标签: javascriptSubmitting a nested formweird behaviorStack Overflow
版权声明:本文标题:javascript - Submitting a nested form, weird behavior - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742023114a2415048.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论