Matt
Matt

Reputation: 127

Can't submit my form using anchor instead of button

<form id="activateform" method="post" action="/admin/changeStatusUser">

    <input type="text" hidden="" value="7" name="userId"></input>
    <a class="icon-5 info-tooltip" title="Activate" href="" onclick="document.getElementById('activateform').submit()"></a>

</form>

Here's my form that I need to submit when clicking the link(Can't use the button because the link has the style already defined). However, it's not working, on click it refreshes the page. However, if I change the anchor to input, everything works... so what am I doing wrong with my anchor?

Upvotes: 1

Views: 114

Answers (3)

Martin
Martin

Reputation: 16292

Change the href="" attribute to href="#"

Upvotes: 7

pisamce
pisamce

Reputation: 533

As others said, change href to # or, another way is to add return false; to onclick handler:

<a class="icon-5 info-tooltip" title="Activate" href="" onclick="document.getElementById('activateform').submit();return false;"></a>

Upvotes: 3

Akshay Khale
Akshay Khale

Reputation: 8371

Change href attribute to # Ex.

<a class="icon-5 info-tooltip" title="Activate" href="#" onclick="document.getElementById('activateform').submit()"></a>

or change it to javascript: Ex.

<a class="icon-5 info-tooltip" title="Activate" href="javascript:" onclick="document.getElementById('activateform').submit()"></a>

Upvotes: 0

Related Questions