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

Thanks, that first link was pretty useful.

Best Regards
SC

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.