473,396 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.writeln('<INPUT TYPE="hidden" NAME="itemName"
VALUE="'+theitem+'" 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.substring(i,i+1) == '[') {
thisitem = 1;
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == ']') {
itemend = i;
thequantity = fulllist.substring(itemstart, itemend);
itemtotal = 0;
itemtotal = (eval(theprice*thequantity));
temptotal = itemtotal * 100;
subtotal = subtotal + itemtotal;
weighttotal = 0;
weighttotal = (eval(theweight*thequantity));
subweight = subweight + weighttotal;
itemlist=itemlist+1;
document.write('<tr><td>'+thequantity+'</td>');
document.writeln('<td>'+thenumber+'</td><td>
'+theitem+'</td><td>'+theprice+'</td><td>'+alterError(itemtotal)+'</td></tr>');

} else if (fulllist.substring(i,i+1) == '|') {
if (thisitem==1) theitem = fulllist.substring(itemstart, i);
if (thisitem==2) theprice = fulllist.substring(itemstart, i);
if (thisitem==3) thenumber = fulllist.substring(itemstart, i);
if (thisitem==4) theweight = fulllist.substring(itemstart, i);
thisitem++;
itemstart=i+1;
}
}
Jul 23 '05 #1
2 5732
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.writeln('<INPUT TYPE="hidden" NAME="itemName"
VALUE="'+theitem+'" 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.substring(i,i+1) == '[') {
thisitem = 1;
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == ']') {
itemend = i;
thequantity = fulllist.substring(itemstart, itemend);
itemtotal = 0;
itemtotal = (eval(theprice*thequantity));
temptotal = itemtotal * 100;
subtotal = subtotal + itemtotal;
weighttotal = 0;
weighttotal = (eval(theweight*thequantity));
subweight = subweight + weighttotal;
itemlist=itemlist+1;
document.write('<tr><td>'+thequantity+'</td>');
document.writeln('<td>'+thenumber+'</td><td>
'+theitem+'</td><td>'+theprice+'</td><td>'+alterError(itemtotal)+'</td></tr>');

} else if (fulllist.substring(i,i+1) == '|') {
if (thisitem==1) theitem = fulllist.substring(itemstart, i);
if (thisitem==2) theprice = fulllist.substring(itemstart, i);
if (thisitem==3) thenumber = fulllist.substring(itemstart, i);
if (thisitem==4) theweight = fulllist.substring(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.getElementById("myHidden").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.location="mypage.asp?item1=shirt&item2=so cks&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******@corsad.net> wrote in message
news:25**************************@posting.google.c om...
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.writeln('<INPUT TYPE="hidden" NAME="itemName"
VALUE="'+theitem+'" 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.substring(i,i+1) == '[') {
thisitem = 1;
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == ']') {
itemend = i;
thequantity = fulllist.substring(itemstart, itemend);
itemtotal = 0;
itemtotal = (eval(theprice*thequantity));
temptotal = itemtotal * 100;
subtotal = subtotal + itemtotal;
weighttotal = 0;
weighttotal = (eval(theweight*thequantity));
subweight = subweight + weighttotal;
itemlist=itemlist+1;
document.write('<tr><td>'+thequantity+'</td>');
document.writeln('<td>'+thenumber+'</td><td>
'+theitem+'</td><td>'+theprice+'</td><td>'+alterError(itemtotal)+'</td></tr>
');
} else if (fulllist.substring(i,i+1) == '|') {
if (thisitem==1) theitem = fulllist.substring(itemstart, i);
if (thisitem==2) theprice = fulllist.substring(itemstart, i);
if (thisitem==3) thenumber = fulllist.substring(itemstart, i);
if (thisitem==4) theweight = fulllist.substring(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
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...
8
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"> ...
23
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...
2
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"...
3
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...
14
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...
19
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
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.