...

View Full Version : How can Imake a cookie to save the user data in this script



inlandti
11-08-2004, 06:37 PM
<html><head><title>dddd</title>
<script language="JavaScript">

var ItemNum=0



function showimage()
{
if (!document.images)
return
document.images.pictures.src=
document.form1.picture.options[document.form1.picture.selectedIndex].value
}

function list()
{
var listarray=new Array()

listarray[0]="12.34"
listarray[1]="22.88"
listarray[2]="10.01"
listarray[3]="16.61"



var itemarray=new Array()
itemarray[0]="widget"
itemarray[1]="dodad"
itemarray[2]="thingy"
itemarray[3]="whirligig"

var location =document.form1.picture.selectedIndex
var imagechoice=document.form1.picture.options[location].text

var locationb =document.form1.num.selectedIndex
var numchoice=document.form1.num.options[locationb].text

if (ItemNum<=5)

{
document.form1.Item[ItemNum].value=imagechoice
document.form1.quan[ItemNum].value=numchoice
}

if(imagechoice==itemarray[0])
document.form1.total[ItemNum].value=listarray[0]*numchoice

else if(imagechoice==itemarray[1])
document.form1.total[ItemNum].value=listarray[1]*numchoice

else if(imagechoice==itemarray[2])
document.form1.total[ItemNum].value=listarray[2]*numchoice

else if(imagechoice==itemarray[3])
document.form1.total[ItemNum].value=listarray[3]*numchoice







ItemNum++


if(document.form1.Item[4].value="")
alert("help")
{
if(imagechoice=="")
alert ("you must choose an Item")
document.form1.Item[ItemNum].value==""
document.form1.total[ItemNum].value==""
document.form1.quan[ItemNum].value==""



if (numchoice=="")
alert ("You must choose a Quantity")
document.form1.Item[ItemNum].value==""
document.form1.total[ItemNum].value==""
document.form1.quan[ItemNum].value==""



}

}





function chkFrm(){

var doc = document['form1'];
var subConf = confirm ("Are you sure you want to empty the cart?" + "\r\n\r\n" + "Click OK to delete," + "or Cancel to return.");

if (subConf == true){
doc.submit();

} else if (subConf == false){
return false;
}
}















</script>




</head><body>


<form name ="form1">
<TABLE border=1>

<TR>
<TH width ="10">Description</TH>
<TH>Quantity</TH>
<TH>Functions</TH>
<TR>
<TD rowSpan=2 ><SELECT name="picture" size="1" onChange="showimage()">
<option selected =""><option value="widget.jpg">widget</option>
<option value="dodad.jpg">dodad</option>
<option value="thingy.jpg">thingy</option>
<option value="whirligig.jpg">whirligig</option></select>

<TD rowSpan=2 align ="center"><SELECT name="num">

<OPTION selected=""><option>1</OPTION>
<option>2</OPTION>
<option>3</OPTION>
<option>4</OPTION></SELECT> </TD>

<TD align ="center"><INPUT type=button value="Add to Cart"onClick="list()" ></TD></TR>
<TR>
<TD align ="center"><input type="button" value="Empty Cart" onClick="chkFrm();" ></TD></TR>





<TR>
<td rowspan=2 width="50"><p align="center"><img src="document.form1.picture.selectedIndex" name="pictures" >
</TD></TR>
<TR>

<TD colspan=2><Table><tr><td align ="center"><strong>Item</strong></td><td align ="center"><strong>Number Ordered</td>
<td align ="center"><strong>Total</td></strong><tr><td align ="center">
<input type=text name="Item"></td><td><input type=text name="quan"></td><td><input type=text name="total"></td></TR>
<tr><td align ="center">
<input type=text name="Item"></td><td><input type=text name="quan"></td><td><input type=text name="total"></td></TR>
<td align ="center">
<input type=text name="Item"></td><td><input type=text name="quan"></td><td><input type=text name="total"></td></TR>
<tr><td align ="center">
<input type=text name="Item"></td><td><input type=text name="quan"></td><td><input type=text name="total"></td></TR>
<tr><td align ="center">
<input type=text name="Item"></td><td><input type=text name="quan"></td><td><input type=text name="total"></td></TR>










</TABLE>
</form>
</body></html>

Willy Duitt
11-08-2004, 07:46 PM
Try doing on a search for a javascript file named: storedValues.js

This prewritten script has the ability to save all of a forms values regardless if they are inputs, checkboxes, radio buttons, options, ect....

.....Willy



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum