473,796 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

for each loop javascript output ASP

I have a for each loop in javascript, of which I need to output to an
ASP array. unfortunantly not too familiar with javascript..

the loop is for items ordered in a shopping cart. they are displayed
as rows of a table. all i need to do is get the same data into an ASP
array to use on the next page, specificaly the +theitem+ and
+thenumber+ variables.

i can pass any one variable like this:
document.writel n('<INPUT TYPE="hidden" NAME="itemName"
VALUE="'+theite m+'" SIZE="40">');

but need a way to get them all. thanks for any help!
-smhh

the javascript loop:

for (var i = 0; i <= fulllist.length ; i++) {
if (fulllist.subst ring(i,i+1) == '[') {
thisitem = 1;
itemstart = i+1;
} else if (fulllist.subst ring(i,i+1) == ']') {
itemend = i;
thequantity = fulllist.substr ing(itemstart, itemend);
itemtotal = 0;
itemtotal = (eval(theprice* thequantity));
temptotal = itemtotal * 100;
subtotal = subtotal + itemtotal;
weighttotal = 0;
weighttotal = (eval(theweight *thequantity));
subweight = subweight + weighttotal;
itemlist=itemli st+1;
document.write( '<tr><td>'+theq uantity+'</td>');
document.writel n('<td>'+thenum ber+'</td><td>
'+theitem+'</td><td>'+thepri ce+'</td><td>'+alterE rror(itemtotal) +'</td></tr>');

} else if (fulllist.subst ring(i,i+1) == '|') {
if (thisitem==1) theitem = fulllist.substr ing(itemstart, i);
if (thisitem==2) theprice = fulllist.substr ing(itemstart, i);
if (thisitem==3) thenumber = fulllist.substr ing(itemstart, i);
if (thisitem==4) theweight = fulllist.substr ing(itemstart, i);
thisitem++;
itemstart=i+1;
}
}
Jul 23 '05 #1
2 5769
bunnyman wrote:
I have a for each loop in javascript, of which I need to output to an
ASP array. unfortunantly not too familiar with javascript..

the loop is for items ordered in a shopping cart. they are displayed
as rows of a table. all i need to do is get the same data into an ASP
array to use on the next page, specificaly the +theitem+ and
+thenumber+ variables.

i can pass any one variable like this:
document.writel n('<INPUT TYPE="hidden" NAME="itemName"
VALUE="'+theite m+'" SIZE="40">');

but need a way to get them all. thanks for any help!
-smhh

the javascript loop:

for (var i = 0; i <= fulllist.length ; i++) {
if (fulllist.subst ring(i,i+1) == '[') {
thisitem = 1;
itemstart = i+1;
} else if (fulllist.subst ring(i,i+1) == ']') {
itemend = i;
thequantity = fulllist.substr ing(itemstart, itemend);
itemtotal = 0;
itemtotal = (eval(theprice* thequantity));
temptotal = itemtotal * 100;
subtotal = subtotal + itemtotal;
weighttotal = 0;
weighttotal = (eval(theweight *thequantity));
subweight = subweight + weighttotal;
itemlist=itemli st+1;
document.write( '<tr><td>'+theq uantity+'</td>');
document.writel n('<td>'+thenum ber+'</td><td>
'+theitem+'</td><td>'+thepri ce+'</td><td>'+alterE rror(itemtotal) +'</td></tr>');

} else if (fulllist.subst ring(i,i+1) == '|') {
if (thisitem==1) theitem = fulllist.substr ing(itemstart, i);
if (thisitem==2) theprice = fulllist.substr ing(itemstart, i);
if (thisitem==3) thenumber = fulllist.substr ing(itemstart, i);
if (thisitem==4) theweight = fulllist.substr ing(itemstart, i);
thisitem++;
itemstart=i+1;
}
}


Your code is confusing, and I am not exactly sure what you are trying to
accomplish. When passing values between a Web page and the server, it
is often useful to do it in a single string, using a delimiter.

If your values do not have spaces, you can use spaces, such as: "item1
item2 item3" etc. If your values have spaces, pick a character that you
know is not allowed in your values, such as ~. Something like this
would work: "Item 1~Item 2~This is item 3~Item 4".

In javascript, if your values are in an array:

var x = new Array( "Item 1", "Item 2", "Item 3" );

You can join them as a string like this:

var y = x.join("~");

This will produce a string in y that looks like this: "Item 1~Item
2~Item 3"

In Javascript, if you have a string that is delimted, you can split it
into an array likewise like this:

var z = y.split("~");

This will create an array z that is identical to x.

So, with that, you know how to use arrays to make a string, and
vice-versa. You can do this to convert an array into a string, and put
it in your hidden value. You can do this in Javascript, if you have a
value that is like this:

<INPUT TYPE=hidden NAME="itemName" VALUE="" ID="myHidden">
<SCRIPT type="text/javascript>
document.getEle mentById("myHid den").value = x.join("~");
</SCRIPT>

Assuming x is an array that you want to send to your ASP page.

Then, on your ASP page, I know that VBScript has a the same join/split
functionality. ASP/VBScript is out of the realm of this group.

Good luck,
Brian
Jul 23 '05 #2
Bunnyman, you can't get there from here. Javascript is a client-wide
technology, ASP is server side. The only way to pass your values to an asp
page is through a querystring:

document.locati on="mypage.asp? item1=shirt&ite m2=socks&item3= shoes"

or through a form:

<form action="mypage. asp" method="get">
<input type=hidden name=item1 value="shirt">
<input type=hidden name=item2 value="socks">
<input type=hidden name=item3 value="shoes">
</form>

Once either happens, you can then process the values any way you like.
--
William Morris
Semster, Seamlyne reProductions
Visit our website, http://www.seamlyne.com, for the most comfortable
historically inspired clothing you can buy!

"bunnyman" <bu******@corsa d.net> wrote in message
news:25******** *************** ***@posting.goo gle.com...
I have a for each loop in javascript, of which I need to output to an
ASP array. unfortunantly not too familiar with javascript..

the loop is for items ordered in a shopping cart. they are displayed
as rows of a table. all i need to do is get the same data into an ASP
array to use on the next page, specificaly the +theitem+ and
+thenumber+ variables.

i can pass any one variable like this:
document.writel n('<INPUT TYPE="hidden" NAME="itemName"
VALUE="'+theite m+'" SIZE="40">');

but need a way to get them all. thanks for any help!
-smhh

the javascript loop:

for (var i = 0; i <= fulllist.length ; i++) {
if (fulllist.subst ring(i,i+1) == '[') {
thisitem = 1;
itemstart = i+1;
} else if (fulllist.subst ring(i,i+1) == ']') {
itemend = i;
thequantity = fulllist.substr ing(itemstart, itemend);
itemtotal = 0;
itemtotal = (eval(theprice* thequantity));
temptotal = itemtotal * 100;
subtotal = subtotal + itemtotal;
weighttotal = 0;
weighttotal = (eval(theweight *thequantity));
subweight = subweight + weighttotal;
itemlist=itemli st+1;
document.write( '<tr><td>'+theq uantity+'</td>');
document.writel n('<td>'+thenum ber+'</td><td>
'+theitem+'</td><td>'+thepri ce+'</td><td>'+alterE rror(itemtotal) +'</td></tr>
');
} else if (fulllist.subst ring(i,i+1) == '|') {
if (thisitem==1) theitem = fulllist.substr ing(itemstart, i);
if (thisitem==2) theprice = fulllist.substr ing(itemstart, i);
if (thisitem==3) thenumber = fulllist.substr ing(itemstart, i);
if (thisitem==4) theweight = fulllist.substr ing(itemstart, i);
thisitem++;
itemstart=i+1;
}
}

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2559
by: Kingdom | last post by:
I Need some serious help here. strugling novis with ASP and javascript any help would be greatly appreciated The script below does exactly what I want it to do for each product on the two passes it makes however I would like the entire script to loop 34 times and on each of those 30 loops also write the product and the price (only) onto the page building a compleate list of all the products selected over the 34 loops ending with a total...
8
1991
by: Mark Constant | last post by:
I have a xslt file and it keeps giving me an EOF error when it reaches the point <xsl:for-each select="lc:Entertainment/lc:$Hardware"> and <xsl:for-each select="lc:Entertainment/lc:$Hardware"> My xslt file looks like this <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
23
2213
by: Mark Anderson | last post by:
A 'for' loop takes 3 arguments (initialize; test; increment). The 'test' must equate as true or false This doesn't work... x = 5; for (y=1; (y==5); y+=1) { alert(x * y); } ...nor does... x = 5;
2
1485
by: jain_tj | last post by:
Could anyone please help me with the following problem My xml file is ============== <fig id="F0000001"> <caption>Caption text</caption> <image id="I0000001" image.class="halftone" image.type="jpg" print="0" width="29-6" depth="23-6" pointer="I0000001.jpg"/> </fig>
3
3116
by: MicroMoth | last post by:
Hi, I'm trying to call a Javascript function within a foreach loop. I am loop over a series of users and I want to call the JS function which opens a new window, passing in the user id to each call for the JS function. So far I've done this: foreach (USER _user in users) { string jscriptString = "<script language='JavaScript'>";
14
2682
by: dawnerd | last post by:
Hi, I am developing a CMS and came across something which has never happened to me before, and I re-wrote the specific script twice, both differently, and still had the same error. I'm not sure if it is apache, or php, or just an error I am not seeing. here is the code: <?php /** * Loop through the resultset
19
2934
by: vamshi | last post by:
Hi all, This is a question about the efficiency of the code. a :- int i; for( i = 0; i < 20; i++ ) printf("%d",i); b:- int i = 10;
3
4665
by: undshan | last post by:
I am writing a code that needs to open a file, create an output file, run through my function, prints the results to the output file, and closes them within a loop. Here is my code: #include <stdlib.h> #include <stdio.h> #include <math.h> #include <string.h> #include "util.h" //Main Loop
2
2748
by: sakat | last post by:
<?php $dbhost = 'unix.lsbu.ac.uk'; $dbuser = 'lrc3'; $dbpass = 'dietdft_'; $dbname = 'lrc3'; // This is an example open a db $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname);
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9533
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10461
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10239
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10190
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7555
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6796
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.