javascript - using $(this) to find the forms submit button -
Using some validation and jQuery Q-tip to show errors.
I want to show the error tip on the same page as variables on the same page and only under the existing type submit button.
This structure is:
& lt; Form action = 'process / reportcomment.php' method = 'post' class = 'reportcommentform' name = 'reportcommentform' & gt; & Lt; Input type = 'hidden' value = '' name = 'commentID' & gt; & Lt; Input type = 'hidden' value = '' name = 'comment' & gt; & Lt; Input class = 'reportcommentsubmit' name = 'submit-report' type = 'submit' value = 'report' & gt; & Lt; / Form & gt;
And then I need to find the submit-report button with jQuery.
I have tried this in my Ajax response:
if (response.cantReport === true) {errorMessage = 'Please wait 30 minutes'; ErrorField = $ (this) .find ('.reportcommentsubmit'); ShowErrorMessage (error message, errorField); }
But no luck.
Thanks for any help!
Try this:
errorField = $ (this) .clostest ('Form'). (Find 'reportcommentsubmit');
Otherwise, you've wrapped the code around $ (this)
, which does not make it equal to the button, but your Wrapping one of the jQuery calls when you come in such a situation, you have to store it like parent
this
;
var _this = this; $ .POST ('address', {}, function (using) {console.log (_this); // $ (here) will not be $ of the button here (this) because there is a lambda function in which the radius Has a claim });
Comments
Post a Comment