Skip to content

Instantly share code, notes, and snippets.

@NoMan2000
Created October 18, 2013 16:04
Show Gist options
  • Save NoMan2000/7043779 to your computer and use it in GitHub Desktop.
Save NoMan2000/7043779 to your computer and use it in GitHub Desktop.
A Pen by Michael Ryan Soileau.
<!DOCTYPE HTML>
<html>
<head>
<title>Event Scheduler</title>
<script language="JavaScript" type="text/javascript">
<!--
function ScheduledEvent(evtdate, evttitle, maxattendees, coordinator, phonenum, email, infourl){
this.evtdate = evtdate;
this.evttitle = evttitle
this.maxattendees = maxattendees;
this.coordinator = coordinator;
this.phonenum = phonenum;
this.email = email;
this.infourl = infourl;
this.PrintEvent = PrintEvent;
}
function PrintEvent()
{
document.write("<p>You have scheduled an event named " + this.evttitle);
document.write(" that will occur on " + this.evtdate + " and allow up to " + this.maxattendees + " attendees. ");
document.write("The event is coordinated by " + this.coordinator + " who can be reached at " + this.phonenum);
document.write(" or by email at " + this.email + ". ");
document.write("More information about the event is available at <a href='" + this.infourl + "'> " + this.infourl + "</a></p>");
}
function IsURL(sURL)
{
if ((sURL.length < 12) || (sURL.indexOf("://", 0) == -1))
return false;
else
return true;
}
function IsEmail(sEmail)
{
if ((sEmail.length < 6) || (sEmail.indexOf("@", 0) == -1))
{
return false;
}
else
return true;
}
function IsNumeric(sNumber)
{
var numberChars = "0123456789.";
var IsNumber=true;
var currentChar;
//loop through the characters to ensure that each is a character that would be included in a positive number
for (i = 0; i < sNumber.length && IsNumber == true; i++)
{
currentChar = sNumber.charAt(i);
if (numberChars.indexOf(currentChar) == -1)
{
IsNumber = false;
}
}
return IsNumber;
}
function Validate() {
with (document.evtForm) {
evt = new ScheduledEvent(evtDate.value, evtTitle.value, maxattendees.value, evtCoordinator.value, phonenum.value, email.value, infourl.value);
}
with (evt)
{
if(evtdate.length < 1)
{
alert("You must enter a date.");
return false;
}
if(coordinator.length < 5)
{
alert("The coordinator name must be at least 5 characters long.");
return false;
}
if(evttitle.length < 1)
{
alert("The title must be at least 1 character long.");
return false;
}
if(maxattendees.length < 1 || !IsNumeric(maxattendees))
{
alert("The maximum number of attendees must be a number");
return false;
}
if(phonenum.length < 1 || !IsNumeric(phonenum))
{
alert("The phone number is required and must be a number");
return false;
}
if(!IsEmail(email))
{
alert("The email address must be at least 6 characters and must contain a @.");
return false;
}
if(!IsURL(infourl))
{
alert("The URL must be at least 12 characters and be a valid URL.");
return false;
}
evt.PrintEvent();
}
return true;
/*
if(
}
*/
}
//-->
</script>
</head>
<body>
<form name= "evtForm" method="post" onsubmit="Validate();">
<table>
<tr>
<td>
Event Date: </td><td><input type=date id="evtDate" /> </td>
</tr>
<tr><td>Title:</td><td> <input id="evtTitle" /></td></tr>
<tr><td>Maximum attendees:</td><td><input type=number id="maxattendees" /> </td></tr>
<tr><td>Event Coordinator: </td><td><input id="evtCoordinator" /></td></tr>
<tr><td>Phone number (numbers only): </td><td><input type=tel id="phonenum" /></td></tr>
<tr><td>Email: </td><td><input type=email id="email" /></td></tr>
<tr><td>More info: </td><td><input type=url id="infourl" /></td></tr>
</table>
<input type=submit value="Submit" />
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment