Search code examples
javascriptformssubmit

How to submit the form using javascript with "this"


Is there any way to submit the current form in which i have the href link like this

<a href="javascript:;" onclick="this.submit();">Save</a>

I want to use same code evrywhere so i can't use any id or class


Solution

  • Submit form using this.form.submit()

    i.e in your case it will be like

    <a href="#" onclick="this.form.submit();">Save</a>
    

    But it highly recommended to use form name

    otherwise if you are comfortable using jquery you can also use jquery closest function

    $(field).closest("form").submit();