I use jQuery validation plugin from here. Is there a way to check if the field is NOT equal to s开发者_Go百科ome string? I have a select element looking like this:
<select id="school_admin" name="school">
<option value="selector">Select...</option>
<option value="UDSM">University of Dar Es Salaam</option>
<option value="ARU">Ardhi University</option>
<option value="IFM">Institute of Finance Management</option>
</select>
As you can see, first option is 'Select...' and I need to check on submit that it's not set to this first item, but to some another actual option. How can I do that quickly?
A better way of coding your select might be to use an optgroup
:
<select id="school_admin" name="school">
<optgroup label="Select a school...">
<option value="selector">Select...</option>
<option value="UDSM">University of Dar Es Salaam</option>
<option value="ARU">Ardhi University</option>
<option value="IFM">Institute of Finance Management</option>
</optgroup>
</select>
The 'select' label is then not selectable.
http://reference.sitepoint.com/html/optgroup
Why not just change the default option value to blank and leverage the metadata support by declaring a class of required on the select. Here is the demo
if($("#item").html() != "string" )
I suggest you leave Select...'s value empty value=""
then simply
if ( ( sel = $('#school_admin').val() ).length ) { ... }
else { .. }
Never used the actual plugin, so you should be able to make it work with its own api
Check the value of the select element, and see if it matches the first one.
if ($('#school_admin').val() != 'selector') {
//Doesn't equal the first one, do your thing
}
精彩评论