Validate if specific value is selected

Hi there,

I have the following line which insets an option to the top of a select. What I would like to do is to check if this value is left as the default and return an alert or a validation message asking the user to select an option apart from the default.

$("select[name='ap']").prepend("<option value='' selected='selected'>Default option</option>");

What would be the best way to do this?


1 Like

But as UI/UX wouldn’t that confuse the user? What if they are ok w/the default?

Yes, I think this should be thought out a bit more.

Why present an option if it isn’t to be selected?

And I’m confused some as I usually define “default” as meaning something like “most often the best choice”

If there aren’t all that many options, maybe radios would be better?

Sometimes there is no default and you want to force the person to actually choose between the options - then you provide a blank option as the initially selected one so that they have to change it. If you didn’t provide that blank option then you’d never know whether they selected the first one because that was their choice or because they forgot to choose. I suppose you could present the options in random order in that situation so that those who forget to choose get randomly distributed across the choices instead of all being assigned to the saem one.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.