Forum Moderators: not2easy
<HTML>
<HEAD>
<TITLE>Homework 9</TITLE>
<style type="text/css">
body { background-color: #CCCCCC;
}p
{
text-align: center;
color: black;
font-family: arial
}
</style>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
order = prompt( "How many chips do you want to purchase? ", 0 ); // user input for chips purchased
// default = 0
username = prompt( "Please enter your first and last name"); // user imput name
useraddress = prompt( "Please enter your address ( house #, street name, city, state, zip code)"); //user imput address
userphonenumber = prompt( "Please enter your phone numer, (#*$!-#*$!-#*$!x)"); //user input phone #
userwebsite = prompt( "Please enter your website, www.yourwebsite.com"); // user input website
useremail = prompt( "Please enter your email address"); // user input email
var response = confirm("Are you sure you want to purchase this many chips?"); //user confirm
if (response == true)
{
alert("Ok just checking!");
}
else
{
alert("You have selected to not purchase any chips");
}
if (order <=0) { //orders < 0
alert("You must purchase at least one chip");
}
if (order > 0 && order<=19 ) { //orders/discounts between 0-19
singlediscount = 0;
multiplediscount = order * 0;
monetarydiscount= order * 110 * singlediscount;
}
else if (order>= 20 && order<=49) { // orders/discounts between 20-49
singlediscount = .02;
multiplediscount = order * .02;
monetarydiscount= order * 110 * singlediscount;
}
else if (order>=50 && order<=79 ) { // orders/discounts betweeb 50-79
singlediscount = .04;
multiplediscount = order * .04;
monetarydiscount= order * 110 * singlediscount;
}
else if (order>=80 && order<=99 ) { //orders/discounts between 80-99
singlediscount = .06;
multiplediscount = order * .06;
monetarydiscount= order * 110 * singlediscount;
}
else if (order >=100) { //orders/discounts greater then 100
singlediscount = .08;
multiplediscount = order * .08;
monetarydiscount= order * 110 * singlediscount;
}
document.write( " Customer name: ", username, "<BR>" ); //user output to the screen
document.write( " Customer address: ", useraddress, "<BR>" );
document.write( " Customer phone #: ", userphonenumber, "<BR>" );
document.write( " Customer email address: ", useremail, "<BR>" );
document.write( " Customer website: ", userwebsite.link("http://www.google.com"),"<BR>");
document.write( " # of chips purchased at $110 per chip = ", order, "<BR>" );
document.write( " Total cost before discount = $ ", order * 110, "<BR>" );
document.write( "Discount in percent (%) = ", singlediscount , "<BR>" ); // display results
document.write( "Discount in monetary amount per chip =$ ", monetarydiscount/order, "<BR>" );
document.write( "Total cost after discount = $" , order * 110 - monetarydiscount, "<BR>" );
document.write( "Total savings from discounts =$ ", monetarydiscount, "<BR>" );
</SCRIPT>
</BODY>
</HTML>
<form>
<fieldset>
<legend>Title</legend>
<input......blah blah>
<input......blah blah>
<textarea......blah blah>
</fieldset>
</form>
1) if you do it all by javascript, then anyone with javascript turned off will not be able to do anything (which is apparently quite a big percentage of people these days)
2) you'd get some basic styling already, even without doing any CSS.
you'd also have many more 'hooks' that you can style. the secret to doing good CSS is including lots of semantic tags in the HTML, which you can style without using classes and IDs. ie...
form{blah blah}
input{blah blah}
textarea{blah blah}
that means you won't have to include lots of unneccesary <div>'s, <span>'s and <br>'s.
you can still do all of your javascript checks on the form data, if you want
It'll validate things like postcodes, email addresses, names, phone numbers, cc numbers, dates. All on the fly. One of the best scripts I ever wrote.
Saves having to do it post submission and make the user fill out everything again.