Вопрос

Currently i have 5 radiobuttons. 4 of them define an certain amount of money. The last one marks a custom field there you can enter a custom amount of money in an input field.

Is it possible, just with HTML, to set the input field "required" only if the the last radiobutton is active.

If it's not possible, is javascript the best way to solve this problem ?

Это было полезно?

Решение

It's not possible to do conditional validation of form fields with HTML only. At most you could manipulate the DOM with javascript to add the required attribute to the <input> element when necessary (i.e. in an onchange event handler for the radio button).

Remember it might be useful to provide fallback behavior for the required attribute for older browsers without HTML5 support.

Note: This other question is pretty much about the same.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top