开发者

Selective Submission of form using <button> tag not working

开发者 https://www.devze.com 2023-03-08 11:52 出处:网络
I want a function to take some values from a form as input and manipulate in the background . I tried but it goes to a url mydomain.com/gtype=selected value . I just want it to do something in the bac

I want a function to take some values from a form as input and manipulate in the background . I tried but it goes to a url mydomain.com/gtype=selected value . I just want it to do something in the background a开发者_开发技巧nd not change the url

I have a fiddle over here. http://jsfiddle.net/4qppX/


You need to return false in your onclick handler.

<button onclick="hihi(this.form.gtype); return false">sub</button>

An alternative is to make the button a non-submitting button by saying type="button"

<button type="button" onclick="hihi(this.form.gtype);">sub</button>

I am not sure about the reasoning for this by the W3C states:

If the element has a form owner, the element must submit the form owner from the button element.


You can also make sure your button is just a button, and not a "submit" control:

<button type='button' onclick='hihi(this.form.gtype)'>sub</button>
0

精彩评论

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