Hi guys I’m a noob to this site.
I have written a simple registration web page, but I don’t know how to make the page show the form named ‘register’ ONLY if the user’s input is satisfactory. How do i do it? I’ve even tried putting the form code into a document.write() ! ?
Here’s the code I have:
<HTML>
<HEAD>Register/Sign in<BR>
<TITLE>SOFASPEND – IN THE BEST POSSIBLE TASTE!</TITLE>
<SCRIPT language=”JavaScript” type=”text/javascript”>
var strInput;
strInput = window.prompt(‘Do you wish to register (1) or are you an existing member (2)?’,”);
//decide which option was chosen
if (strInput==1)
{
document.write(‘<BR>WELCOME – WE WILL SET UP YOUR ACCOUNT DETAILS NOW<BR>’);
}
else
{
if (strInput==2)
{
document.write(‘SHOP UNTIL YOU DROP<BR>’);
}
else
{
strInput = window.prompt(‘Are you a member (1) or do you wish to register (2)?’,”);
if (strInput==1)
{
document.write(‘<BR>WELCOME – WE WILL SET UP YOUR ACCOUNT DETAILS NOW<BR>’);
}
else
{
if (strInput==2)
{
document.write(‘<BR>SHOP UNTIL YOU DROP<BR>’);
}
}
}
}
</SCRIPT>
<SCRIPT>
/* A password checking application with an event-driven interface
function isNumeric(aCharacter)
{
return (aCharacter >= ‘0’) && (aCharacter <= ‘9’)
};
function isLowerCase(aCharacter)
{
return (aCharacter >= ‘a’) && (aCharacter <= ‘z’)
};
function isUpperCase(aCharacter)
{
return (aCharacter >= ‘A’) && (aCharacter <= ‘Z’)
};
function isAlpha(aCharacter)
{
return (isUpperCase(aCharacter) || isLowerCase(aCharacter))
};
function isAlphaNumeric(aCharacter)
{
return (isAlpha(aCharacter) || isNumeric(aCharacter))
};
function checkLength(aString)
{
return (aString.length >= 4) && (aString.length <= 8)
};
function checkLegal(aString)
{
var result;
result = true;
for (var position = 0; position < aString.length; position = position + 1)
{
if (!isAlphaNumeric(aString.charAt(position)))
{
result = false
}
};
return result
};
function checkFirst(aString)
{
return isAlpha(aString.charAt(0))
};
/* Slightly different implementation of the checkHasDigit() function, which uses a for loop instead of a while loop
function checkHasDigit(aString)
{
result = false;
for (var position = 0; position < aString.length; position = position + 1)
{
if (isNumeric(aString.charAt(position)))
{
result = true
}
};
return result
}
function checkPass(password)
/* checks that a password conforms to a specified format
{
var errorFound;
errorFound = false;
if (!checkLength(password))
{
errorFound = true;
window.alert( ‘length not in range (4-8)’)
};
if (!checkLegal(password))
{
errorFound = true;
window.alert( ‘illegal characters in password (must all be alphanumeric)’)
};
if (!checkFirst(password))
{
errorFound = true;
window.alert( ‘first character must be alphabetic’)
};
if (!checkHasDigit(password))
{
errorFound = true;
window.alert( ‘must contain at least one digit (but not the first character)’)
};
if (!errorFound)
{
window.alert( ‘password accepted’)
}
};
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME = “register”>
<!–textboxes–><BR>
First Name<BR><INPUT NAME = “txtFName” TYPE = “TEXT” VALUE = ”><BR>
Surname<BR><INPUT NAME = “txtSName” TYPE = “TEXT” VALUE = ”><BR>
Choose your password<BR><INPUT NAME = “txtPassword” TYPE = “TEXT” VALUE = ”>
<!–submission button–>
<BR><BR><INPUT NAME = “btnSubmit” TYPE = “BUTTON” VALUE = ‘Submit’ ONCLICK = “checkPass(document.register.txtPassword.value)”>
<BR>
</FORM>
</BODY>
</HTML>