Hi, what l want to do is once a user has changed an amount (which will be a number between 1 & 99) in a text box, l want a cookie, which contains a list of information about various items, to be updated. i.e to change one items amount to the value the user just placed in the text box.
The cookie looks like this: cost=20.00/Smoking/1::cost=25.00/Slips And Trips/4::cost=25.00/Substance/2::
Where cost is the name of the cookie and each item is separated by '::'. The last digit in each item is the one l want to update.Here is a code segement:
// 'for loop' splits each item in thisCookie array at the '=' sign, this takes out the cookie name from the string (i.e 'cost')
for(j=0; j<thisCookie.length-1; j++){
thisCookies = thisCookie[j].split("=");
// 'for loop' splits each item in 'thisCookies' array at each '/' and then places each part in a table
for (i=1; i<thisCookies.length; i++){
pieces = thisCookies.split("/");
document.write('<tr><td width="335">');
document.write(pieces[1]);
document.write('</td><td width="95">');
document.write('<input name="amount'+j+'" type="text" id="amount_'+j+'" value="'+pieces[2]+'" onblur="ChangeNumber('+pieces[1]+',?????);" size="2" maxlength="2" />');
document.write('</td><td width="78">');
document.write("£");
document.write(pieces[0]);
document.write('</td></tr>');
total += parseFloat(pieces[0]);
}
}
Not sure how to get the value of the text box into the '?????' bit though. Here is the code for the function that is called:
function ChangeNumber(strObjId, nNb){
MyArrayOfItem = document.cookie.split("::");
for(i=0;i<MyArrayOfItem.length-1;i++){
MyItemStuff = MyArrayOfItem.split("/")
if(MyItemStuff[1]== strObjId){
var MyNewItemStuff = MyItemStuff[0]+"/"+MyItemStuff[1]+"/"+nNb;
MyArrayOfItem=MyNewItemStuff;
}
}
var ret = "";
for(i=0;i<MyArrayOfItem.length-1;i++){
if(ret == "") ret = MyArrayOfItem;
else ret += "::" + MyArrayOfItem;
}
MyCookie = ret+"::";
document.cookie = MyCookie;
alert(MyCookie);
}
What l need is to get 'nNb' to equal the value of the text box, which means that the '?????' has to equal the value of the text box. Any suggestions?
The cookie looks like this: cost=20.00/Smoking/1::cost=25.00/Slips And Trips/4::cost=25.00/Substance/2::
Where cost is the name of the cookie and each item is separated by '::'. The last digit in each item is the one l want to update.Here is a code segement:
// 'for loop' splits each item in thisCookie array at the '=' sign, this takes out the cookie name from the string (i.e 'cost')
for(j=0; j<thisCookie.length-1; j++){
thisCookies = thisCookie[j].split("=");
// 'for loop' splits each item in 'thisCookies' array at each '/' and then places each part in a table
for (i=1; i<thisCookies.length; i++){
pieces = thisCookies.split("/");
document.write('<tr><td width="335">');
document.write(pieces[1]);
document.write('</td><td width="95">');
document.write('<input name="amount'+j+'" type="text" id="amount_'+j+'" value="'+pieces[2]+'" onblur="ChangeNumber('+pieces[1]+',?????);" size="2" maxlength="2" />');
document.write('</td><td width="78">');
document.write("£");
document.write(pieces[0]);
document.write('</td></tr>');
total += parseFloat(pieces[0]);
}
}
Not sure how to get the value of the text box into the '?????' bit though. Here is the code for the function that is called:
function ChangeNumber(strObjId, nNb){
MyArrayOfItem = document.cookie.split("::");
for(i=0;i<MyArrayOfItem.length-1;i++){
MyItemStuff = MyArrayOfItem.split("/")
if(MyItemStuff[1]== strObjId){
var MyNewItemStuff = MyItemStuff[0]+"/"+MyItemStuff[1]+"/"+nNb;
MyArrayOfItem=MyNewItemStuff;
}
}
var ret = "";
for(i=0;i<MyArrayOfItem.length-1;i++){
if(ret == "") ret = MyArrayOfItem;
else ret += "::" + MyArrayOfItem;
}
MyCookie = ret+"::";
document.cookie = MyCookie;
alert(MyCookie);
}
What l need is to get 'nNb' to equal the value of the text box, which means that the '?????' has to equal the value of the text box. Any suggestions?
