Here is my problem,
I have a select box where i need to validate if the val() becomes 0, then append a text insed a span with class error stating that ‘Please select a value’. Else need to remove that div. These happens when i click the submit button. Here is my code,
if ($('.combo option:selected[value==0]')) {
var error_span = $("div.info-cont ul.map-list li span.right")
.append("<br>Please select an appropriate value")
.addClass('error');
} else {
}
Now the problem is, if a value is selected in the selectbox, my appended span should get removed. Any help. Thanks in advance…
I just want to explain this:
To check if the selected item from dropdown has value 0, you can use the following:
Then, it will be simpler if you already put the error message somewhere in the document. All you need to do is show/hide it. For example:
And the javascript (+ jquery):
Here is another example. Useful if you avoid IDs (perhaps you have dynamically generated dorpdowns):