I am trying to create a input text box when a user enters in his/hers room number and submits it, it will send them to a specific url map. There will be a list of numbers and each one will link to a certain url. But I am pretty much a newb when it comes to javascript so if anyone has any suggestions on how I might be able to incorporate into the vaildation script below I would truly appreciate it.
<HTML>
<HEAD>
<TITLE>Untitled Page</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<SCRIPT LANGUAGE="JavaScript">
function validateroom(field) {
var valid = "0123456789-";
var hyphencount = 0;
if (field.length!=4 && field.length!=10) {
alert("Invalid characters in your room number."
return false;
}
for (var i=0; i < field.length; i++) {
temp = "" + field.substring(i, i+1);
if (temp == "-" hyphencount++;
if (valid.indexOf(temp) == "-1" {
alert("Invalid characters in your room number. Please try again."
return false;
}
if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-") {
alert("The hyphen character should be used with a properly formatted 4 digit room humber, like '1234'. Please try again."
return false;
}
}
return true;
}
// End -->
</script>
</HEAD>
<form name=room onSubmit="return validateroom(this.room.value)">
Room #: <input type=text size=5 name=room>
<input type=submit value="Submit">
</form>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE>Untitled Page</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<SCRIPT LANGUAGE="JavaScript">
function validateroom(field) {
var valid = "0123456789-";
var hyphencount = 0;
if (field.length!=4 && field.length!=10) {
alert("Invalid characters in your room number."
return false;
}
for (var i=0; i < field.length; i++) {
temp = "" + field.substring(i, i+1);
if (temp == "-" hyphencount++;
if (valid.indexOf(temp) == "-1" {
alert("Invalid characters in your room number. Please try again."
return false;
}
if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-") {
alert("The hyphen character should be used with a properly formatted 4 digit room humber, like '1234'. Please try again."
return false;
}
}
return true;
}
// End -->
</script>
</HEAD>
<form name=room onSubmit="return validateroom(this.room.value)">
Room #: <input type=text size=5 name=room>
<input type=submit value="Submit">
</form>
</BODY>
</HTML>