Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
The following code works in Chrome Version 47.0.2526.73 but on Firefox and IE 11 doesn't work. Any ideea why

HTML:
HTML
<form action="@Url.Content("~/Account/LogOn/")" method="post" id="login_form">
     <input type="text" id="username" name="username" placeholder="Username" value=""/>
     <input type="password" id="password" name="password" placeholder="Password" value=""/>
     <button id="btnLogin" class="btn btn-inverse pull-right" type="submit" onclick="OpenPage()" >Sign In</button>
</form>


JavaScript:
JavaScript
function OpenPage() {
    $('body').empty().load('../../../Content/LoaderHtml/loader.html');
    return false;
}

The code must call an ActionResult method from MVC

Only the onclick event get's fired in Firefox and IE (in Chrome the form also triggers the Controlller's method), if i remove the onclick event everthing works well in firefox and ie and chrome

I need to trigger the onclick event and also to post the form to server (The Chrome behaviour is ok, but how can i make this work even in firefox and IE)

Edit:
I've tried also
HTML
onclick="return OpenPage()"
and in javascript
JavaScript
return true;


Thanks for help!
Posted
Updated 3-Dec-15 21:52pm
v3
Comments
F-ES Sitecore 4-Dec-15 3:45am    
What onclick event? What does OpenPage have to do with this, where is it connected to what you're doing?
[no name] 4-Dec-15 3:49am    
Sorry, my bad i've updated the question
F-ES Sitecore 4-Dec-15 3:53am    
What behaviour are you looking for? You're updating the existing page and also replacing it. The click event will amend the page, but submitting the form will replace the whole page therefore destroying your previous update. What is it you're looking to do?
[no name] 4-Dec-15 4:00am    
what i'm trying to achive is to replace the body of a login page with another html content that has a CSS animation (loader.html) that acts as a loading screen until the ActionResult method returns the view (which will replace the loader.html content). This is how it behaves on Chrome but in firefox and ie only the onclick event is triggered the MVC action is not called
F-ES Sitecore 4-Dec-15 4:24am    
Does removing the "return false" from OpenPage make a difference? Something else to try is a bit hacky, but your OpenPage can start a setTimeout for a short time, 100ms, and in the timeout do the load work.

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