开发者

Selecting a radio button isn't an event?

I have a html form which contains group of radio buttons.

When one of them is selected, the form attribute "action" should be executed as well as the method "get".

开发者_如何学运维

But the problem is, selecting the radio button doesn't recognized as an event !!

and if I changed the radio buttons to submit buttons the click on the submit button will be recognized as an event and the action will take place, do you have any idea why??


HTML forms do not submit unless someone presses a submit button.

You can use Javascript to get your radio buttons to submit the form:

<input type="radio" onclick="this.form.submit();" />

Be aware, however, that a radio button that submits the form is something a user generally does not expect. Use with caution.


Only inputs of type submit and image cause form submission. If you want checking a radio button to submit you will have to use javascript. Just call

onclick="document.forms["myform"].submit();"


You can use onclick event of radio object and then check for selected (checked) radio button. After that you can submit your form.


I think it's because the submit button is the only way to validate the html form. Try to use javascript. Create a function, and check at first if the radiobutton is selected. If is it, continue the validation. You can call the function in the "onSubmit". The bad side of this, is that the submit button will still being the trigger.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜