usert4jju7 usert4jju7 - 2 months ago 9
jQuery Question

Javascript/jquery - onclick of a button

I'm stuck with a strange problem where a javascript function isn't getting invoked when I click on

submit button(LOG IN)
from inside a form.

<html>
<head>
<title></title>
<script>
$('#loginBtn').click(function () {
$(this).html('<img src="http://www.bba-reman.com/images/fbloader.gif" />');
});
</script>
</head>
</html>


Is there anything different I should do here? I'm unable to figure this out. Please could I ask for help?

Answer

Remove the extra ) at the end of function hideBtn().

It should look like this

function hideBtn(){
  alert('hello');
};

<html>
    <head>
    <title></title>
    <link rel="stylesheet"  type="text/css"   href="app/js/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet"  type="text/css"   href="app/js/bootstrap/css/bootstrap-theme.min.css">
    <link rel="stylesheet"  type="text/css"   href="app/css/bootsnipLogin.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script type="text/javascript" src="app/js/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="app/js/login.js"></script>
    <link rel="shortcut icon" href="app/image/favicon.ico" />

    </head>

    <body >
    <div class="container">
        <div class="card card-container">
        <br/>
        <center><img src="app/image/wd-logo.gif"></center>
        <br/><br/>
        <img id="profile-img" class="profile-img-card" src="app/image/avatar_2x.png" />
        <br/>
        <p id="profile-name" class="profile-name-card"></p> 
        <form class="form-signin" action="" method="post">
            <input  id="username" name="username"  placeholder="User Name"  class="form-control" required autofocus>
            <br/><br/><br/>
            <input  type="password"  id="password" name="password"  placeholder="Password" class="form-control" required >
            <br/><br/><br/>
            <div align="center">
            <span id = "errorspan"><?php echo $error; ?></span>
            </div>
            <br/><br/><br/>
            <button class="btn btn-lg btn-primary btn-block btn-signin" type="submit" name="submit" id="loginBtn">SIGN IN</button>
        </form><!-- /form -->
        </div><!-- /card-container -->
    </div><!-- /container -->   
          <script>
    $('#loginBtn').click(function(){
    //  alert('as');
        $(this).html('<img src="http://www.bba-reman.com/images/fbloader.gif" />');
    });
    </script> 
    </body> 
</html>