What's wrong with this code?


#1

$(document).ready(function(){
	$(#register).click(function() {
		var username = $(#Username).val();
		var firstname = $(#Name).val();
		var lastname = $(#Lastname).val();
		var email = $(#Email).val();
		var password $(#Password).val();
		var repassword $(#Repassword)
			if(username == "" || firstname == ""||lastname == ""|| email == ""|| password == "" || repassword == ""){
				alert("please fill all fields...!!!!!!");
			} else if ((password.length) < 8){
				alert("Password should atleast be 8 characters in length");
			} else if(!(password).match(repassword)){
				alert("Your passwords does not match")
			}
	}
}

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<!DOCTYPE html>
<html>
	<head>
	<link style= "text/css" rel = "stylesheet" href ="cssindie.css">
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
	<script type="text/javascript" src="script.js"></script>
	<title></title>
	</head>
	<body>
		<div class= "body">
			
		</div>
		<div class= "Login">
		<label> Username <label>
		<input type ="text" username="dname" id="Username">
		<label> first name <label>
		<input type ="text" name="dname" id="Name">
		<label> lastname <label>
		<input type ="text" name="dname" id="Lastname">
		<label> Email <label>
		<input type ="text" name="dname" id="Email">
		<label>Password</label>
		<input type ="text" name="dname" id="Password">
		<label>Rewrite password</label>
		<input type ="text" name="dname" id="Repassword">	
		<label> What is your line of work <label>
		<input type ="checkbox" name="dname" id="whWork">
		<label>not on the list write it down</label>
		<input type ="text" name="dname" id="Work">
		<input type ="button" name="dname" id="register" value="Register">
		
				
		</div>
	</body>
</html>
</body>
</html>

#4

The link to the Jquery code does not work


#5

Which course is this from?


#6

No course and if im right that's why im placed in the corner bar and the link is not eaven there sorry here ya go



</head>
<body>
<!DOCTYPE html>
<html>
	<head>
	<link style= "text/css" rel = "stylesheet" href ="cssindie.css">
	<script type='text/javascript' src='script.js'></script>
	<title>Studioblock</title>
	</head>

#7

i thought i do not know why i cant post it

/*<!DOCTYPE html>
<html>
	<head>
	<link style= "text/css" rel = "stylesheet" href ="cssindie.css">
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
	<script type="text/javascript" src="script.js"></script>
	<title></title>
	</head>
*/

#8

well this is the only thing i have as link though i wa strying to post the whole Doctype and head part but here is the only links i have

	<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
	<script type="text/javascript" src="script.js"></script>

#9
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>

#11

what do you mean by formatted it's just that i do not get why the links for the Jquery does not work


#12

I formatted your code, meaning I made it look better, so you could see it easier.

I am looking at your code now, I will tell you if I find something.


#13

ah okey Thanx i need some help so thanx alot actually


#14

@jibblyj, i formatted the code, it is now fully visible.

@jenson1234, apart from what is wrong with the code, it seems you are trying to create some kind of login/register form?

I hope you thought this through in terms of security.


#15

well yea i have im just needing help with the fault of the link or if it's just that the code does not work


#16

How did you think this through in terms of security? I will look at the code, for of it i would just use the require attribute, as demonstrated here


#17

right now im thinking of making the page and need to connect the files with eachother it's either that that does not work or it's the code in the Jquery page that does not work!:smiley:


#18

take a look at these lines:

$(#register).click(function() {
        var username = $(#Username).val();

there are two mistakes here, already, you are missing ' inside $():

$('#register').click(function() {
        var username = $('#Username').val();

and this goes for many lines to follow, you can fix it, and then post an updated version of your code

Please read this post about markdown so your code/indent will show.

#register are names of html elements, in this case id's, they need ', without it, they would be js/jquery variable, which they are not.


#19

$(document).ready(function(){
	$('#register').click(function() {
		var username = $('#Username').val();
		var firstname = $('#Name').val();
		var lastname = $('#Lastname').val();
		var email = $('#Email').val();
		var password $('#Password').val();
		var repassword $('#Repassword')
			if(username == "" || firstname == ""||lastname == ""|| email == ""|| password == "" || repassword == ""){
				alert("please fill all fields...!!!!!!");
			} else if ((password.length) < 8){
				alert("Password should atleast be 8 characters in length");
			} else if(!(password).match(repassword)){
				alert("Your passwords does not match")
			}
	}
}

still not working though


#20

Well, then i would look at it again, i just was not planning on doing something boring like inserting a lot of apostrophes.


#21

This code was so full of bugs....

Right, i fixed it:

$(document).ready(function(){
    $('#register').click(function() {
        var username = $('#Username').val();
        var firstname = $('#Name').val();
        var lastname = $('#Lastname').val();
        var email = $('#Email').val();
        var password = $('#Password').val();
        var repassword = $('#Repassword').val();
            if(username == "" || firstname == ""||lastname == ""|| email == ""|| password == "" || repassword == ""){
                alert("please fill all fields...!!!!!!");
            } else if ((password.length) < 8){
                alert("Password should atleast be 8 characters in length");
            } else if(!(password).match(repassword)){
                alert("Your passwords does not match");
            }
      });
});

biggest changes i made, these two lines:

        var password $('#Password').val();
        var repassword $('#Repassword');

no equal sign after variable declaration, repassword doesn't have a .val().

Other important changes, last two lines:

	}
}

added missing ); at both lines. If you look at the opening lines:

$(document).ready(function(){
	$('#register').click(function() {

you will see the closing requires both a ) and }

Now, i really want to hear what you are using this for, so i know this is secure.


#22

why do you wanna know if this is secure im not doing this for any big party company if that's what you think im playing around with code and im trying to make a register page for a website im doing can i ask why you feel this is not safe?


#23

Where are you going to store the login data? Just a thought

Well, you currently use clientside javascript. Lets say you set up a website, with this jscode, i request the page + js code, and it gets loaded into my browser, which means i can alter the js code super easy, to bypass any checks you build in with javascript, making it super insecure.

You can of course do client side validation, but you are going to need server side validation as well