for each loop javascript output ASP

Discussion in 'Javascript' started by bunnyman, Apr 5, 2004.

  1. bunnyman

    bunnyman Guest

    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;
    }
    }
    bunnyman, Apr 5, 2004
    #1
    1. Advertising

  2. 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
    Brian Genisio, Apr 6, 2004
    #2
    1. Advertising

  3. 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=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" <> wrote in message
    news:...
    > 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;
    > }
    > }
    William Morris, Apr 6, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Blair
    Replies:
    1
    Views:
    396
    Eliyahu Goldin
    Aug 3, 2005
  2. Tjerk Wolterink

    xsl:for-each for each 3 elements problem

    Tjerk Wolterink, Nov 3, 2004, in forum: XML
    Replies:
    3
    Views:
    416
    Tjerk Wolterink
    Nov 3, 2004
  3. Pat Maddox
    Replies:
    6
    Views:
    141
    Marcin Mielżyński
    Jan 20, 2006
  4. Igor Nn
    Replies:
    7
    Views:
    426
    Johnny Morrice
    May 28, 2011
  5. Isaac Won
    Replies:
    9
    Views:
    348
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page