Jump to content

What am I doing wrong?


DatDudeFuddPucker

Recommended Posts

<!DOCTYPE html>
<head>
</head>
<body>
<header>
	<script>
		functionScheduledEvent (evtdate, evtTitle, maxattendees, coordinator, phonenum, email, infour1)
		{
		this.evtdate = evtdate;
		this.ectTitle = evtTitle:
		this.maxattendees = maxattendees;
		this.coordinator = coordinator;
		this.phonenum = phonenum;
		this.email = email;
		this.infourl = infourl;
		}

		functionPrintEvent (){
		document.write (" <p> You have scheduled an event name " + this.evtTitle);
		document.write (" that will occur on " + this.evtdate + " and allow up to " + this.maxattendees. ");
		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 <ahref='" + this.infourl + "'> + "</a></p>");
		}
		functionValidate(){
			with (document.evtForm){
					evt = new ScheduledEvent (evtDate.value, evtTitle.value,, maxattenddes.value, evtCoordinator.value, phonenum.value, email.value, infourl.value);
				}
			with (evt){
					evt.PrintEvent ();
				}
						return true;
			}
	</script>
</header>
	<form name = "evtForm" method="post">
		<table>
		<tr><td>Event Date: </td><td><input type="data" 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>

I have the code copied from my lab manual. I do not understand what I am doing wrong. Everytime I hit submit it just clears all the fields and the message that is supposed to come up does not come up. I would appreciate any help with this. I have just begun my learning of java script.

Link to comment
Share on other sites

There are a few problems.

First, document.write() will always remove everything on the page before printing its content. Don't use it. You can replace it with innerHTML.

Secondly, the with statement should never be used. It's bad coding practice.

 

The name attribute on the <form> element is deprecated, you should give it an id attribute instead and access the element using its ID:

<form id="evtForm" method="post">
document.getElementById("evtForm");

Whichever book you're getting this code from is at least a decade out of date.

Link to comment
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
×
×
  • Create New...