html - Check for default value upon form submission with JQuery -
I'm trying to use JQuery to check on submission if a field input has a default value, And, if this happens, I have worked till one point to present and alert the user. But no matter what I've put in the input field, the submission has been closed and the text has been changed into alert text.
Here is JQuery:
$ ('# ($ (' # subject '). Val (' at least one subject, separated by commas') {$ ('# Topics'). RemoveClass ('inactive'); $ ('note'); $ ('# subject'). Val ('please include at least one subject'); return back;} return false; });
Once the original text has been cleared, the text has been changed to inform the user. Now I have a string instead of the variable, and For some reason it only works (partially) if I In some places '=='. Now, firstly, if the condition works in the focus function, but there is no other situation. I currently have this code:
$ ('#' ') .focus (function () {If (this.value ==' at least one subject is separated by commas') {$ (this) .val ('');} Otherwise (this.value = = 'Please include at least one subject') {$ (this) .val (''); $ (This) .removeClass ('notice');}}); $ ('# subject'). Blurred ( Work () (if (this.value == '') {$ (this) .val ('at least one subject, separated by commas'); $ (this). AddClass ( 'Inactive');}});
Obviously, my GPT's mastery, well, it's not like that. But I appreciate any help.
With jQuery you set the value of a form like this:
<(> here 'Text')But if you want to get the value, as it is to check against the value, then you will use the val () function with such a parameter, such as:
if ($ ('# subject'). Val () == 'At least one topic, separated by commas' {...}
< / Div>
Comments
Post a Comment