Yes, you can configure the button - with a listener, where when you press the button you can stop the form submission. Form view is the default behavior for a button 'type submit (important) in the form.
The event method, preventDefault (or returnValue = false for the window event, depending on the event model the browser follows) will prevent this default behavior, sending behavior. I also stop programming (MSIE evt. Model = cancelBubble).
For example, for the following button of type 'submit':
<button type="submit" id="logout" name="logout" value="Log Out">Log Out</button>
Add an x-browser event listener for this particular button. For example, assuming testlogout is the name of your function that controls what happens when the button is clicked, the following can be used to configure the listener:
var logoutBtn = (document.getElementById && document.getElementById('logout')) || (document.all && document.all['logout']) || document.forms[formname].elements['logout'] || null; if (logoutBtn) { if (logoutBtn.addEventListener) { logoutBtn.addEventListener('click',testlogout,false); } else if (window.attachEvent) { logoutBtn.attachEvent('onclick',testlogout); } else { //legacy: logoutBtn.onclick = testlogout; //...logic for document.layers support, etc. } }
Then, in the testlogout function, which will automatically pass the event, you check all the conditions. According to your conditions, use event.preventDefault or returnValue, depending on what the browser supports. They replace inline ' return false . For instance:
function testlogout(e) { e = e || window.event; //... your logic here... e.stopPropagation?e. stopPropagation():(e.cancelBubble?e.cancelBubble():""); e.preventDefault?e.preventDefault():e.returnValue=false; return false; // in case all else fails? }
The past event has its own set of properties, of course, whose names change, again, depending on the model that the browser follows. These properties, for example, identify the pressed target button.
Listening models of the current event do not pay attention to "return false". For example, the command "return false" will be omitted, so to speak. But do not worry while you use what they understand.
Hope this helps solve the real underlying problem. Reading on DOM events and event models will refine the available methods and properties.