0

I am using the following HTML:

<form action="/User/Account/LogOff" id="logoutForm" method="post">
   <button class="float-left submit-button" title="Logoff">Logoff</button>
</form>

I would like to replace this with:

<form action="/User/Account/LogOff" id="logoutForm" method="post">
   <div class="button" id="logout" title="Logout">
      <span>Logout</span>
   </div>
</form>

Is there a way that I can catch a click on the div#logout and use this as a submit for the form? I saw this for a link:

<a href="javascript:document.getElementById('logoutForm').submit()">Logout</a>

But how could I do it for a DIV like mine?

2
  • just use a submit button if you are not use any client side validation .that's good don't use unnecessary js ,for logout you dosent even want a form .it can be a link Commented Jan 15, 2013 at 6:15
  • You can try the solution in this link stackoverflow.com/questions/6366087/submit-data-on-div-click Commented Jan 15, 2013 at 6:16

1 Answer 1

2

Add this into your DIV:

   <div class="button" id="logout" onclick="javascript:document.getElementById('logoutForm').submit();" title="Logout">

EDIT 1: Thanks for pointing out.

   <div class="button" id="logout" onclick="submitForm()" title="Logout">

Javascript:

 function submitForm()
 {
      document.getElementById('logoutForm').submit();
 }
Sign up to request clarification or add additional context in comments.

1 Comment

Don't put javascript: prefix in onXXX attributes. That's only needed for href links.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.