PDA

View Full Version : javascript help plz


newbie_20
06-01-2005, 11:22 AM
i need to write the selected payment method in the new window but am unsure how to do it. i also have problems working out the final total and i have to add an if statement saying that if the total is greater than 200 than $12 is added for delivery if less than 200 than its 15 and am unsure now to do this.

this is for an assessment piece and programming isnt my strongest subject so any help (in simple terms if possible! :P) would be great

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>xmas4</TITLE>
<META NAME="Generator" CONTENT="Stone's WebWriter 3.5">
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 6.00.2900.2627" name=GENERATOR>
<SCRIPT>
<!-- Hide from incompatible browsers
//This program will allow people to click on a link to show a certain product and order which Christmas item they desire.
//each function will assign a name to an eventto call on rather then repeating the commands.
//Each variable declared assigns a word repserentation to line of code.


function newPage()
{
DispWin = window.open('','NewWin', 'toolbar=no,status=no,width=300,height=200')
message = "<ULul><BR><LIli><b>name: </b>" + order.box1.value ;
message += "<BR><LIli><b>address: </b>" + order.box2.value;
message += "<BR><LIli><b>phone: </b>" + order.box3.value + "</ULul>";
message += "<BR><LIli><b>age: </b>" + order.box4.value + "</ULul>";
message += "<BR><LIli><b>you are paying by: </b>" + order.value+ "</ULul>";
message += "<BR><input type='button' value='close' onclick='self.close();' />"
DispWin.document.write(message)


}

window.status = " Merry Christmas! Merry Christmas! ";
function scrollStatusBar()

{
var message = window.status;
window.status = message.substring(1) + message.substring(0, 1);
}
function calcPrice(i)
{
var price = document.order.price[i].value;
var qty = document.order.qty[i].value;
var total = price * qty;
document.order.total[i].value = total.toFixed(2);
if ( document.order.tick[i].checked!==true)
document.order.tick[i].checked==true;
}

function checkQty(i)
{
if (document.order.tick[i].checked==true)
{
if (document.order.qty[i].value == "")
{
alert("Please enter the quantity you require!");
document.order.qty[i].focus();
}
}
else
{
document.order.qty[i].value = "";
document.order.total[i].value = "";
}
}

//work out the total order for the user
//using a increment operator (++) allows the user to increase the order/quantity if they wish
//parsefloat will convert a string symbol to a floating-point number (decimals)

function totalOrder()
{
var yourTotal=0;
for(i=0; i<13; ++i)
{
if (document.order.tick[i].checked==true)
{
var thisAmount = parseFloat(document.order.total[i].value);
yourTotal += thisAmount;
}
}
yourTotal = "$" + yourTotal.toFixed(2);
document.order.grandTotal.value==yourTotal;
}
//getMonth method will return a number (1-12) repsrenting the month: getYear() will return two digits for the year (eg-99)
//declaring variables in order to gather the current date to work out how many days until Xmas

var days = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

var today = new Date();
var myDay = today.getDate();
var myMonth = today.getMonth();
var myYear = today.getYear();

var myDate = myDay + " " + months[myMonth]+ ", " + myYear;

//formaltes a count down method for days left until Xmas
//create a alert box to inform user how many days left until Xmas

function countDown()
{
var xmasDay = new Date(2005, 12, 25);
var now = new Date(myYear, myMonth, myDay);
var daysToXmas = Math.round((xmasDay - now) / 86400000);
alert("Only " + daysToXmas + " sleeps until Christmas!" );
}


// Stop hiding from incompatible browsers -->
</SCRIPT>
</HEAD>
<body onload="setTimeout('countDown()', 10000);setInterval('scrollStatusBar()',100)"
BACKGROUND="SNFLAKE2.WMF">

<a onmouseover="window.status = ' Merry Christmas! '" onmouseout="window.status = ' Merry Christmas! '"></a>
<FORM name=order>
<H1>Xmas Order Page</H1>

<TABLE border=1>
<TBODY>
<TR>
<TD>description</TD>
<TD>Select</TD>
<TD>Price</TD>
<TD>Quantity</TD>
<TD>Total</TD></TR>
<TR>
<TD><A HREF="Delicate glass angel 5cm.htm">Delicate glass angel 5cm</A></TD>
<TD><input type="checkbox" name="tick" onclick="checkQty(0);"/> </TD>
<TD><input type="text" name="price" value="14.95" READONLY /></TD>
<TD><input type="text" name="qty" border="0" onchange="calcPrice(0);"/ SIZE=10></TD>
<TD><input type="text" name="total" /></TD>
</TR>
<TR>
<TD><A HREF="green bauble.htm">green bauble</A></TD>
<TD><input type="checkbox" name="tick" onclick="checkQty(0);"></TD>
<TD><input type="text" name="price" value="11.95" READONLY /></TD>
<TD><input type="text" name="qty" border="0" onchange="calcPrice(1);"/ SIZE=10></TD>
<TD><input type="text" name="total" /></TD>
</TR>
<TR>
<TD><A HREF="red bauble.htm">red bauble</A></TD>
<TD><input type="checkbox" name="tick" onclick="checkQty(0);"></TD>
<TD><input type="text" name="price" value="11.95" READONLY /></TD>
<TD><input type="text" name="qty" border="0" onchange="calcPrice(2);"/ SIZE=10></TD>
<TD><input type="text" name="total" /></TD>
</TR>
<TR>
<TD><A HREF="blue bauble.htm">blue bauble</A></TD>
<TD><input type="checkbox" name="tick" onclick="checkQty(0);"></TD>
<TD><input type="text" name="price" value="11.95" READONLY /></TD>
<TD><input type="text" name="qty" border="0" onchange="calcPrice(3);"/ SIZE=10></TD>
<TD><input type="text" name="total" /></TD>
</TR>
<TR>
<TD><A HREF="3 baubles.htm">3 baubles</A></TD>
<TD><input type="checkbox" name="tick" onclick="checkQty(0);"></TD>
<TD><input type="text" name="price" value="26.95" READONLY /></TD>
<TD><input type="text" name="qty" border="0" onchange="calcPrice(4);"/ SIZE=10></TD>
<TD><input type="text" name="total" /></TD>
</TR>
<TR>
<TD><A HREF="red bow.htm">red bow</A></TD>
<TD><input type="checkbox" name="tick" onclick="checkQty(0);"></TD>
<TD><input type="text" name="price" value="4.95" READONLY /></TD>
<TD><input type="text" name="qty" border="0" onchange="calcPrice(5);"/ SIZE=10></TD>
<TD><input type="text" name="total" /></TD>
</TR>
<TR>
<TD><A HREF="blue bow.htm">blue bow</A></TD>
<TD><input type="checkbox" name="tick" onclick="checkQty(0);"></TD>
<TD><input type="text" name="price" value="4.95" READONLY /></TD>
<TD><input type="text" name="qty" border="0" onchange="calcPrice(6);"/ SIZE=10></TD>
<TD><input type="text" name="total" /></TD>
</TR>
<TR>
<TD><A HREF="candy cane.htm">candy cane</A></TD>
<TD><input type="checkbox" name="tick" onclick="checkQty(0);"></TD>
<TD><input type="text" name="price" value="3.95" READONLY /></TD>
<TD><input type="text" name="qty" border="0" onchange="calcPrice(7);"/ SIZE=10></TD>
<TD><input type="text" name="total" /></TD>
</TR>
<TR>
<TD><A HREF="candle centrepeice.htm">candle centrepeice</A></TD>
<TD><input type="checkbox" name="tick" onclick="checkQty(0);"></TD>
<TD><input type="text" name="price" value="19.95" READONLY /></TD>
<TD><input type="text" name="qty" border="0" onchange="calcPrice(8);"/ SIZE=10></TD>
<TD><input type="text" name="total" /></TD>
</TR>
<TR>
<TD><A HREF="outside light.htm">outside light</A></TD>
<TD><input type="checkbox" name="tick" onclick="checkQty(0);"></TD>
<TD><input type="text" name="price" value="29.95" READONLY /></TD>
<TD><input type="text" name="qty" border="0" onchange="calcPrice(9);"/ SIZE=10></TD>
<TD><input type="text" name="total" /></TD>
</TR>
<TR>
<TD><A HREF="santaface.htm">santaface</A></TD>
<TD><input type="checkbox" name="tick" onclick="checkQty(0);"></TD>
<TD><input type="text" name="price" value="12.95" READONLY /></TD>
<TD><input type="text" name="qty" border="0" onchange="calcPrice(10);"/ SIZE=10></TD>
<TD><input type="text" name="total" /></TD>
</TR>
<TR>
<TD><A HREF="santas hat.htm">santas hat</A></TD>
<TD><input type="checkbox" name="tick" onclick="checkQty(0);"></TD>
<TD><input type="text" name="price" value="12.95" READONLY /></TD>
<TD><input type="text" name="qty" border="0" onchange="calcPrice(11);"/ SIZE=10></TD>
<TD><input type="text" name="total" /></TD>
</TR>
<TR>
<TD><A HREF="rocking horse.htm">rocking horse</A></TD>
<TD><input type="checkbox" name="tick" onclick="checkQty(0);"></TD>
<TD><input type="text" name="price" value="129.95" READONLY /></TD>
<TD><input type="text" name="qty" border="0" onchange="calcPrice(12);"/ SIZE=10></TD>
<TD><input type="text" name="total" /></TD>
</TR>
<TR>
<TD><A HREF="wreath.htm">wreath</A></TD>
<TD><input type="checkbox" name="tick" onclick="checkQty(0);"></TD>
<TD><input type="text" name="price" value="39.95" READONLY /></TD>
<TD><input type="text" name="qty" border="0" onchange="calcPrice(13);"/ SIZE=10></TD>
<TD><input type="text" name="total" /></TD>
</TR>
<TR>
<TD colspan="4" align="right" >grand Total</TD>
<TD><input type="text" name="grandTotal " /></TD>
</TR>
</TBODY>
</TABLE>
<br />
<br />
<input type = "button" value="Total Order" onclick="totalOrder();" />
<br />
<br />


<BR><BR>
<h4> Payment Methods & Personal Details </h4>
<P>name:&nbsp;<INPUT size=30 name=box1></P>
<P>address:&nbsp;<INPUT size=40 name=box2></P>
<P>postcode:&nbsp;<INPUT size=7 name=box3></P>
<P>telephone:&nbsp;<INPUT size=15 name=box4></P>
<P>Age:&nbsp;<INPUT size=10 name=box5></P>


<INPUT TYPE=radio NAME=value value="cheque" onClick=" var message= 'you are paying by cheque'; alert(message)"> cheque<BR>
<INPUT TYPE=radio NAME=value value="money order" onClick=" var message= 'you are paying by money order'; alert(message)"> money order<BR>
<INPUT TYPE=radio NAME=credit card value="credit card" onClick=" var message= 'you are paying by credit card. Please fill out your details below'; alert(message)"> credit card<BR>

<P>credit card number:&nbsp;<INPUT size=10 name=box6></P>
<P>expiry date:&nbsp;<INPUT size=10 name=box7></P><BR>
<INPUT onclick=newPage(); type=button value="display page">

</FORM>
<!-- WebWriter AutoDato -->Last updated 1.6.2005<!-- WW -->
</body>
</HTML>