javascript - My onclick not working the second time -
i trying change attribute within form, whenever user clicks the sign or register. form change accordingly, once user clicks on register can no longer click login.
<?php session_start(); if(isset($_post['submit'])) { include_once("php/config/database.php"); $email = strip_tags($_post['email']); $dbpassword = strip_tags($_post['password']); $email = stripslashes($email); $dbpassword = stripslashes($dbpassword); $email = mysqli_real_escape_string($conn, $email); $dbpassword = mysqli_real_escape_string($conn, $dbpassword); $sql = ("select * 'users' email='$email' , password='$dbpassword' limit 1"); $query = mysqli_query($conn, $sql); $row = mysqli_fetch_array($query); $userid = $row['userid']; $dbpass = $row['password']; if($dbpassword == $dbpass) { $_session['email'] = $email; $_session['userid'] = $userid; header("location: account.php"); } else { echo "you didn't enter correct details!"; } } ?> <!doctype html> <html > <head> <meta charset="utf-8"> <title>background</title> <link rel="stylesheet" href="css/style.css"> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script> </head> <body> <form action="index.php" method="post" id="search-theme-form"> <div class="box"> <h1 id="logintoregister"> login </h1> <div class="group show"> <input class="inputmaterial" type="text" name="firstname" /> <label>first name</label> </div> <div class="group show"> <input class="inputmaterial" type="text" name="surname" /> <label>surname</label> </div> <div class="group"> <input class="inputmaterial" type="email" name="email" required/> <label>email</label> </div> <div class="group"> <input class="inputmaterial" type="password" id="password" name="password" required/> <label>password</label> </div> <div class="group show"> <input class="inputmaterial" type="password" id= "confirm_passwor" /> <label>confirm password</label> </div> <button id="buttonlogintoregister" type="submit" name= "submit">login</button> <p id="plogintoregister"> registering, accept terms , conditons</p> <p id="textchange" onclick="register()">sign up</p> </div> </form> <!-- related demos --> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script> </body> </html>
js file
function register(){ var cont = 0; cont++; if(cont==1){ $('.box').animate({height:'600px'}, 550); $('.show').css('display','block'); $('#logintoregister').text('register'); $('#buttonlogintoregister').text('register'); $('#plogintoregister').text("sei gia' registrato?"); $('#textchange').text('login'); $('#search-theme-form').removeattr("action").attr("action", "signup_destination.php"); } else { $('.show').css('display','none'); $('.box').animate({height:'365px'}, 550); $('#logintoregister').text('login'); $('#buttonlogintoregister').text('login'); $('#plogintoregister').text("non sei iscritto?"); $('#textchange').text('register'); $('#search-theme-form').removeattr("action").attr("action", "index.php"); cont = 0; } }
you keep reseting cont var each time function runs,
var cont = 0;
so enter first part of if.
take var count out of function:
var cont = 0; function register(){ .. .. . }
this way wont reset each time function runs 0 , rest should work.
Comments
Post a Comment