Online Advertising - ROKR E6 - Gavin Newsom - Skype - Reference And Education Articles

PDA

View Full Version : Problem with an alert not popping up ( < newbie )


Mythic Fr0st
Nov 30th 2006, 7:07 pm
Well, the problem is, that it should pop up, if your password is less than 7 chars, and should pop up if your username is less than 4 characters, but it doesnt, im not sure why, i only started learning javascript today, can anyone help?

<html>
<head>
<h1>
<b>Welcome</b>
</h1>
<br>
</head>

<body>
Username <input type="text" size"=15" name="user">
<br />
<br />
Password <input type="text" size"=15" name="pw">

<input type="submit" value="Submit">

<form onsubmit="return validateUser(this);">
</form>
<form onsubmit="return validatePw(this);">
</form>
<script type="text/javascript">
<form>
function validateUser(form)
{ if (form.elements["user"].value.length > 3);
{ return true; }
else { alert("Your username must be at least 4 characters long.");
return false; } }

function validatePw(form)
{ if (form.elements["pw"].value.length > 6);
{ return true; }
else { alert("Your password must be at least 7 characters long.");
return false; } }
</script>

</form>
</body>
</html>

Any help appreciated

lbalance
Dec 2nd 2006, 12:20 am
wow, that code looks jacked up.
im going to modify it for what looks correct, but not tested.



<html>
<head>
<script type="text/javascript">
function validateForm(){
if (document.forms['form1'].user.value.length <= 3){
alert("Your username must be at least 4 characters long.");
return false;
} else
if (document.forms['form1'].pw.value.length <= 6){
alert("Your password must be at least 7 characters long.");
return false;
} else {
return true;
}
}
</script>
</head>

<body>
<h1>
<b>Welcome</b>
</h1>
<br>
<form name="form1" onSubmit="return validateForm();">
Username <input type="text" size="15" name="user">
<br />
<br />
Password <input type="text" size="15" name="pw">

<input type="submit" value="Submit">
</form>
</body>
</html>

pushkar
Dec 2nd 2006, 1:34 am
<html>
<head>
<h1>
<b>Welcome</b>
</h1>
<br>
</head>
<script type="text/javascript">
function validateUser(frm)
{
if (document.frm.username.value.length > 3)
{ return true; }
else
{
alert("Your username must be at least 4 characters long.");
return false;
}

if(document.frm.pwd.value.length > 6)
{ return true; }
else
{
alert("Your password must be at least 7 characters long.");
return false;
}

}

</script>
<body>
<form onsubmit="return validateUser(this);" name=form1 id=form1 method=post >
Username <input type="text" size"=15" name="user id="username"">
<br />
<br />
Password <input type="text" size"=15" name="pw" id="pwd">
<input type="submit" value="Submit">
</form>
</body>
</html>

U Can try this.
<script type="text/javascript">
function SubMe()
{
if (document.form1.username.value.length > 3)
{ return true; }
else
{
alert("Your username must be at least 4 characters long.");
return false;
}

if(document.form1.pwd.value.length > 6)
{ return true; }
else
{
alert("Your password must be at least 7 characters long.");
return false;
}

document.form1.submit();
}
</script>
<input type="button" value="Submit" ID="Submit1" onclick="SubMe();">

lbalance
Dec 2nd 2006, 8:31 am
<h1>
<b>Welcome</b>
</h1>
<br>


move this to the <body>