|
-
Aug 27th, 2001, 05:02 AM
#1
Thread Starter
Hyperactive Member
Been battling for weeks!!! Please help...
Hello,
PLEASE!!!! help me with this one - I've been battling for weeks and weeks.
My problem is that I do not know jscript very well which means that I will
need some sample code - please.....
This is what I want to do..
I have 2 pages.
The first has 2 selectboxes - the one is filled with products and the other
is a "shopping list". The user can choose a product from the product list,
click on add and that product is then moved to the "shopping list". You can
add as many products to the shopping list as you wish!!
On this first page I have a link to another page which in turn has a link BACK to
the first page again. My problem is that when the user added all his products to
the shopping list on page one and then moves to the "next page" and then moves BACK to
the first page - the products which he initially added must still be displayed in the
shopping list - it must NOT be initialized again, so that he can the just add more products
to those already there!!
I know this is a long explanation etc, but PLEASE copy these 2 pages to see what I mean - I'm
ripping my hair out here!!
Code for page one
Code:
<html>
<script language="JavaScript">
var k = 0;
var l = 1;
var oLastCombo = null;
var ooLastCombo = null;
// holds the reference to the last combo box selected
function addOption(object,text,value) {
var defaultSelected = false;
var selected = false;
var optionName = new Option(text, value, defaultSelected, selected)
object.options[object.length] = optionName
k=k+1
}
function copySelected(fromObject,toObject) {
if (fromObject != null)
{
var i = fromObject.selectedIndex
var varTest = fromObject.options[i].text;
for (var i=0, l=fromObject.options.length;i<l;i++) {
{ if (fromObject.options[i].selected)
{
addOption(toObject,fromObject.options[i].text,fromObject.options[i].value)
}
}
}
fromObject = fromObject.selectedIndex = 0
oLastCombo = null;
}
};
function ResetLast(oldObject) {
{
if (oldObject != null)
oldObject = oldObject.selectedIndex = 0;
}
}
//--></script>
<head>
<base target="_self">
<title>VB FORUM - HELP!!</title>
</head>
<body bgcolor="#FFFFFF" topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td valign="top"><form id="frmprov" method="post" name="frmprov">
<div align="center"><center><table border="0" cellSpacing="1"
style="BORDER-BOTTOM: thin ridge; BORDER-LEFT: thin ridge; BORDER-RIGHT: thin ridge; BORDER-TOP: thin ridge"
width="20%">
<tbody>
<tr>
<td noWrap vAlign="top" width="33%"><div align="left"><table border="0" width="20%">
<tbody>
<tr>
<td width="50%" style="font-family: Arial" align="left"><select name="D16" size="1"
onfocus="javascript:ResetLast(oLastCombo),oLastCombo=this;"
style="font-family: Century Gothic; font-size: 8pt; width: 72mm">
<option value="prod1">prod1</option>
<option value="prod2">prod2</option>
<option value="prod3">prod3</option>
<option value="prod4">prod4</option>
<option value="prod5">prod5</option>
<option value="prod6">prod6</option>
<option value="prod7">prod7</option>
<option value="prod8">prod8</option>
</select></td>
</tr>
</tbody>
</table>
</div></td>
<td align="middle" noWrap vAlign="top" width="33%"> <div align="center"><center><p><a
href="javascript:copySelected(oLastCombo,frmprov.select2);"><img border="0"
src="images/add.gif" alt="Add an item to Your Shopping Basket" WIDTH="94" HEIGHT="21"></a><br>
<br>
<br>
<br>
<br>
<a href="nextpage.html">next page</a></td>
<td align="center" noWrap vAlign="top" width="33%"><select multiple name="select2"
size="10" style="FONT-FAMILY: Century Gothic; FONT-SIZE: 8pt; WIDTH: 72mm">
</select></td>
</tr>
</tbody>
</table>
</center></div>
</form>
</td>
</tr>
</table>
</body>
</html>
CODE FOR PAGE 2
Code:
<html>
<head>
<title>Next Page</title>
</head>
<body>
<p align="center"><a href="vbforum.html">First page</a></p>
</body>
</html>
-
Aug 27th, 2001, 10:54 AM
#2
Frenzied Member
If you are doing a shopping cart, you must persist the values if you want to see them from page to page. The best way to do this is to use a database and store an ID for the user along with all of the state data (what data is IN the cart). Write a cookie to the user's browser with the ID that will be retrieved upon entry to each page and then used to retrieve the state values from the database. Then just populate your selects appropriately.
oOOo--oOOo
__ /\/\onte96
oOOo--oOOo
Senior Programmer/Analyst
MCP
[email protected]
[email protected]
Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..
-
Aug 27th, 2001, 02:27 PM
#3
Thread Starter
Hyperactive Member
Hi monte96,
Here's the BIG problem!! I CANNOT use ASP in this page - ie pagename.asp (or maybe I can???). The reason why I say this is the following....
I actually have 15 different select boxes with about 100 items per select - ie 1500 products in total. These options within the selects are HARDCODED - NOT read from a DB.
Now, when I name this page "pagename.asp" it loads VERY slowly, BUT when I name it "pagename.HTML" it only loads slow the FIRST time, but everytime after that it's as quick as a flash - obviously because it is cached.
I DO persist my values to the next page. All I do to get the values is...
Code:
for i = 1 to NoOfProds
myvar = Request.Form("select2")(i)
next
My problem is when going BACK to the HTML page!!??
SO I think there are 2 questions/problems here...
1.) How can I prevent the page from loading VERY slowly by using ASP - as far as I have seen it cannot be done, because it is not cached when NOT named *.HTML. I'm sure if I can sort this SPEED/CACHING problem out I will manage to do what I want to do using ASP.
2.) How can I then, using javascript, store all products chosen by the user in a db OR cookie or whatever (page one) AND then RETRIEVE it again, using javascript from the cookie,db and populate my "shopping basket".
Please guys, I dont know where to anymore - ANY help - I know it's a bit of a mess right now.
Thanks,
T
-
Aug 27th, 2001, 08:32 PM
#4
Frenzied Member
1) Use a DB. Never hard code stuff like that. It is a maintenance nightmare.
2) Index the table(s).
3) Try making your back button not just go back to the other page but submit to it again. Make the other page able to determine where the user is coming from forwards or backwards.
oOOo--oOOo
__ /\/\onte96
oOOo--oOOo
Senior Programmer/Analyst
MCP
[email protected]
[email protected]
Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|