Issue in event.PreventDefault()

Posted by Prathiba on Stack Overflow See other posts from Stack Overflow or by Prathiba
Published on 2013-11-11T03:49:32Z Indexed on 2013/11/11 3:52 UTC
Read the original article Hit count: 136

I'm using twitter bootstrap in my application. i gave e.preventDefault for link button in $(document).reday(), but it is not working.

Here is my code:

Master page:

<a id="lnkLogout" href="javascript:void(0);" onclick="PageLogout();"><i class="icon-off">
                            </i>Logout</a>

 <script type="text/javascript" language="javascript">
        $(document).ready(function () {
            $('#lnkLogout').click(function (e) { e.preventDefault(); });         
        });  
 function PageLogout() {
         //Code for logout from the application....
        }                
    </script>

SampleDefaultPage.aspx :

<div class="row-fluid">
                            <div class="form-horizontal">
                                <h4 class="header blue bolder smaller">
                                    Contact</h4>
                                <div class="control-group">
                                    <label for="form-field-email" class="control-label">
                                        Email</label>
                                    <div class="controls">
                                        <input type="text" style="width:200px;" data-val="true" data-val-required="Mobile Number is required."  id="txtEmail">
                                        <div class="space-3">
                                        </div>
                                        <span data-valmsg-replace="true" data-valmsg-for="txtEmail" class="field-validation-valid text-warning red"></span>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label for="form-field-website" class="control-label">
                                        Phone Number</label>
                                    <div class="controls">
                                        <input type="text" style="width:200px;" id="txtPhno">                             
                                    </div>
                               </div>                                                                                                       
                        </div>

I have given txtEmail as mandatory field. if i left that field blank and click on Logout button in Master page, it says txtEmail is required. i dint do any validation in Logout onclick event. I have given preventDefault for Logout link. But still facing an issue. I should be able to logout even though txtEmail is left blank.

Thank you all in advance for your response.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery