Jump to content

Javascript function not executing on click

SilicateWielder

Hey guys, I am trying to write a simple webpage that redirects the user after the correct password is entered. I currently only know javscript so that's what i'm limited to in terms of password verification. When I click Submit the function does not execute or I have written something wrong.

 

Can anyone tell me what i'm doing wrong and how to fix it?

 

HTML:

<HTML>	<HEAD>		<TITLE>Personal Web Archive Test</TITLE>		<LINK rel="stylesheet" type="text/css" href="global_style.css">	</HEAD>		<BODY>		<SCRIPT src="login.js"></SCRIPT>				<DIV class="title">			<H1>Personal Archive Sign-in Page</H1>		</DIV>				<TABLE class="main">			<TR>				<TD class="left">left</TD>								<TD class="cent">					<CENTER>						<P>Please enter your password to continue:</P>						<DIV id="error"></DIV>						<P><INPUT name="PassField" type="text">						<BUTTON type="button" onclick="submit();">Submit</BUTTON></P>					</CENTER>				</TD>								<TD class="right">right</TD>			</TR>		</TABLE>			</BODY></HTML>

Javascript:

adminpass = "1234";function submit() {	pasword = document.getElementById("PassField").value;		if (password == adminpass) {		base = window.location.substr(0, window.location.length - 9);		window.location = base + "home.html";	}	else {		document.getElementById("error").textContent = "ERROR: Wrong password.";	}}

My procrastination is the bane of my existence.

I make games and stuff in my spare time.

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Quick look says your PassField needs an ID.
 
I usually use something like this:

<input type="password" id="l_password" name="l_password" class="input_field" onfocus="wmarkFocus(this, 'Password');" onblur="wmarkBlur(this, 'Password');" value="Password"/>

PS:

function wmarkFocus(txtElem, strWmark) { if (txtElem.value == strWmark)  {  txtElem.value = '';  txtElem.style.color = '#000000';  } }function wmarkBlur(txtElem, strWmark) { if (txtElem.value == '')  {  txtElem.value = strWmark;  txtElem.style.color = '#888888';  } }

PPS:
Does your server support PHP?

Link to comment
Share on other sites

Link to post
Share on other sites

Line 4 of your Javascript you have a spelling mistake. Missing an 's' in password. Define variable 'pasword' and then do a comparison with variable 'password'.

i5 3570k - MSI Z77 GD65 - 16GB Corsair Vengeance - Galaxy GTX 780 - Corsair AX650 - Custom CPU Loop - Corsair 650D - OCZ Agility 4 128GB - WD Black 640GB

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×