0

Hey Guys,

I came across the 'required' attribute for input tags in HTML5, and it just super handy.

But I was wondering, if there is workaround for dependent inputs using just the required attribute.

Like:

Say I have a select box, which has certain options. Depending on the user selection, the user may have to fill out extra information in the form (which is required).

I know how to do this with JS etc. But since I came across the required attribute I am curious, if this is achievable. That would be super!

Thanks.

Best Regards

2
Contributors
3
Replies
6
Views
5 Years
Discussion Span
Last Post by ravoras
0

Thanks, that first link was pretty useful.

Best Regards
SC

0

I managed to figure this out, incase anyone is interested!

All I needed to do was to use a script that sets the required attribute for all the dependent fields!

var newPassword = document.profile_form.newPassword.value

if(newPassword!="") {
        document.getElementById('confirmPassword').setAttribute('required', 'required');
} else {
        document.getElementById('confirmPassword').removeAttribute("required");
}

It wasn't even that hard, I guess its just coding roadblocks that we all run into occasionally.

Cheers

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.