Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
How do i call Submit button using javascript in MVC 4 ?
I want to call logout submit button on click of log out link. Below is my code,

HTML
using (Html.BeginForm("logout", "angular", FormMethod.Post, new { id = "submitForm" }))
     {

     <button type="submit" id="logoutForm" class="btn btn-success">logout</button>
     }

     <a id="fgd" href="java<!-- no -->script:document.getElementById('logoutForm').submit()">Log off</a>


But it is not working :(

i tried the same using jquery as well but not working. What is the problem here? How to do this?
Posted
Comments
Sergey Alexandrovich Kryukov 15-Apr-15 9:16am    
It makes no sense. There is no such concept, "call a button".
—SA

You can either call the buttons click event:
JavaScript
document.getElementById('logoutForm').click();


Or, call the forms submit event:
JavaScript
document.forms[0].submit();


... hope it helps.
 
Share this answer
 
Comments
Am Gayathri 15-Apr-15 9:36am    
This Works :)
hypermellow 15-Apr-15 9:37am    
Glad it helped :-)
Mohammad Areeb khan 12-Nov-20 17:45pm    
It works for me..... Thanks a lot
It makes no sense. There is no such concept, "call a button".
To submit anything means sending appropriate HTTP request. To do it bypassing standard Web form mechanism, you can use Ajax: http://en.wikipedia.org/wiki/Ajax_(programming)[^].

I would like to note that your question and attempt are rather the sign of not very reasonable design, not just code.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900