I'm trying to use JQuery to check upon submission if a field input has the default value, and, if it does, to stop submission and alert the user. What I have works up to a point. But no matter what I put into the input field, submission is stopped and the text is changed to the alert text.
Here is the JQuery:
$('#submitQuestion').submit(function() {
if($('#topic').val('at least one topic, separated by commas')
{
$('#topic').removeClass('inactive');
$('#topic').addClass('notice');
$('#topic').val('Please include at least one topic');
return false;
}
return false;
});
The other problem I have is blanking out the default text once the text has been changed to notify the user. Right now I just have strings instead of variables, and for some reason it only works (partially) if I use '==' in certain places. Right now, the first if condition in the focus function works, but not the elseif condition. Currently I have this code:
$('#topic').focus(function(){
if(this.value=='at least one topic, separated by commas')
{
$(this).val(' ');
} elseif(this.value=='Please include at least one topic')
{
$(this).val(' ');
$(this).removeClass('notice');
}
});
$('#topic').blur(function(){
if(this.value==' ')
{
$(this).val('at least one topic, separated by commas');
$(this).addClass('inactive');
}
});
Obviously, my mastery of JQuery is, well, not as such. But I appreciate any help.