subroutine issue in asp page

Discussion in 'ASP General' started by sjsean, Aug 8, 2007.

  1. sjsean

    sjsean Guest

    I've written an asp page in order to handle an array for a simple
    shopping cart. What I am trying to accomplish is "deleting" one or
    more of the items by basically setting one of the array values to 0 so
    that the item won't be considered for further use. I've been
    successful in determining which checkboxes are checked but it seems
    that my code will set all the items to zero because my conditional
    statement isn't working as I expect. Any suggestions are appreciated.

    <script type="text/vbscript">

    sub refresh()


    <% for i = 0 to Session("cartMaxUsed")%>
    if document.getElementById(i).checked = True then
    <% cartArray(13,i)=0 %>
    end if
    <%next%>

    <%session("cartArray")=cartArray%>

    end sub



    </script>
     
    sjsean, Aug 8, 2007
    #1
    1. Advertising

  2. sjsean

    Evertjan. Guest

    sjsean wrote on 08 aug 2007 in microsoft.public.inetserver.asp.general:

    > I've written an asp page in order to handle an array for a simple
    > shopping cart. What I am trying to accomplish is "deleting" one or
    > more of the items by basically setting one of the array values to 0 so
    > that the item won't be considered for further use. I've been
    > successful in determining which checkboxes are checked but it seems
    > that my code will set all the items to zero because my conditional
    > statement isn't working as I expect. Any suggestions are appreciated.
    >
    > <script type="text/vbscript">


    This is clientside vbs [IE only], not asp serverside vbs.

    >
    > sub refresh()


    clientside sub

    >
    > <% for i = 0 to Session("cartMaxUsed")%>


    serverside loop

    > if document.getElementById(i).checked = True then


    clientside if

    > <% cartArray(13,i)=0 %>


    serverside reaction to if

    > end if
    > <%next%>
    >
    > <%session("cartArray")=cartArray%>


    etc.

    > end sub
    >


    >
    > </script>


    As asp code only prepares the html stream for the client/browser,
    it is finshed before the client starts executing
    the clientside defunct sub.


    Please rethink what you want to do.


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Aug 8, 2007
    #2
    1. Advertising

  3. sjsean

    sjsean Guest

    On Aug 8, 1:15 am, "Evertjan." <> wrote:
    > sjseanwrote on 08 aug 2007 in microsoft.public.inetserver.asp.general:
    >
    > > I've written an asp page in order to handle an array for a simple
    > > shopping cart. What I am trying to accomplish is "deleting" one or
    > > more of the items by basically setting one of the array values to 0 so
    > > that the item won't be considered for further use. I've been
    > > successful in determining which checkboxes are checked but it seems
    > > that my code will set all the items to zero because my conditional
    > > statement isn't working as I expect. Any suggestions are appreciated.

    >
    > > <script type="text/vbscript">

    >
    > This is clientside vbs [IE only], not asp serverside vbs.
    >
    >
    >
    > > sub refresh()

    >
    > clientside sub
    >
    >
    >
    > > <% for i = 0 to Session("cartMaxUsed")%>

    >
    > serverside loop
    >
    > > if document.getElementById(i).checked = True then

    >
    > clientside if
    >
    > > <% cartArray(13,i)=0 %>

    >
    > serverside reaction to if
    >
    > > end if
    > > <%next%>

    >
    > > <%session("cartArray")=cartArray%>

    >
    > etc.
    >
    > > end sub

    >
    > > </script>

    >
    > As asp code only prepares the html stream for the client/browser,
    > it is finshed before the client starts executing
    > the clientside defunct sub.
    >
    > Please rethink what you want to do.
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress)


    That is essentially what I had determined, but can anyone offer an
    alternative approach to solving my initial problem? Would there be a
    way to update an array so that certain items are no longer "active".
    How would one go about using a checkbox to make the item inactive in a
    sense? I know with javascript there are more possibilities to remove
    the item from the array, but I'm not as skilled in that language and I
    think I would still suffer the same issues as I do now. Is the only
    answer to post the form back to itself and update the values that
    way?

    thanks for any suggestions.
     
    sjsean, Aug 9, 2007
    #3
  4. sjsean

    Rob ^_^ Guest

    Hi sjsean,

    When updateing from your session array back to the client page/form.

    <% for i = 0 to Session("cartMaxUsed")
    if cartArray(13,i)=0 then
    %>
    <input type="checkbox" name="C1_<%=i%>" " id="chk_<%=i%>" value="ON">
    <% else %>

    <input type="checkbox" name="C1_<%=i%>" " id="chk_<%=i%>" value="ON"
    checked>
    <% end if %>

    When reading from your shopping cart form and updating your session array...

    <% for i = 0 to Session("cartMaxUsed")
    if request("C1_" & i) = "ON" then
    cartArray(13,i) = 1
    else
    cartArray(13,i)=0
    end if

    '''''''' Regards.
    "sjsean" <> wrote in message
    news:...
    > On Aug 8, 1:15 am, "Evertjan." <> wrote:
    >> sjseanwrote on 08 aug 2007 in microsoft.public.inetserver.asp.general:
    >>
    >> > I've written an asp page in order to handle an array for a simple
    >> > shopping cart. What I am trying to accomplish is "deleting" one or
    >> > more of the items by basically setting one of the array values to 0 so
    >> > that the item won't be considered for further use. I've been
    >> > successful in determining which checkboxes are checked but it seems
    >> > that my code will set all the items to zero because my conditional
    >> > statement isn't working as I expect. Any suggestions are appreciated.

    >>
    >> > <script type="text/vbscript">

    >>
    >> This is clientside vbs [IE only], not asp serverside vbs.
    >>
    >>
    >>
    >> > sub refresh()

    >>
    >> clientside sub
    >>
    >>
    >>
    >> > <% for i = 0 to Session("cartMaxUsed")%>

    >>
    >> serverside loop
    >>
    >> > if document.getElementById(i).checked = True then

    >>
    >> clientside if
    >>
    >> > <% cartArray(13,i)=0 %>

    >>
    >> serverside reaction to if
    >>
    >> > end if
    >> > <%next%>

    >>
    >> > <%session("cartArray")=cartArray%>

    >>
    >> etc.
    >>
    >> > end sub

    >>
    >> > </script>

    >>
    >> As asp code only prepares the html stream for the client/browser,
    >> it is finshed before the client starts executing
    >> the clientside defunct sub.
    >>
    >> Please rethink what you want to do.
    >>
    >> --
    >> Evertjan.
    >> The Netherlands.
    >> (Please change the x'es to dots in my emailaddress)

    >
    > That is essentially what I had determined, but can anyone offer an
    > alternative approach to solving my initial problem? Would there be a
    > way to update an array so that certain items are no longer "active".
    > How would one go about using a checkbox to make the item inactive in a
    > sense? I know with javascript there are more possibilities to remove
    > the item from the array, but I'm not as skilled in that language and I
    > think I would still suffer the same issues as I do now. Is the only
    > answer to post the form back to itself and update the values that
    > way?
    >
    > thanks for any suggestions.
    >
     
    Rob ^_^, Aug 9, 2007
    #4
  5. sjsean

    Evertjan. Guest

    Rob ^_^ wrote on 09 aug 2007 in microsoft.public.inetserver.asp.general:

    > <% for i = 0 to Session("cartMaxUsed")
    > if cartArray(13,i)=0 then
    > %>
    > <input type="checkbox" name="C1_<%=i%>" " id="chk_<%=i%>" value="ON">
    > <% else %>
    >
    > <input type="checkbox" name="C1_<%=i%>" " id="chk_<%=i%>" value="ON"
    > checked>
    > <% end if %>


    What does that extra " afer the name=".." do???

    I would not use the value="ON" of it is not checked.
    I would not use a set value at all, since "on" is default,
    and testing for empty string for not-checked is even simpler.

    It can be done more easily like this:

    <% for i = 0 to Session("cartMaxUsed") %>
    <input type="checkbox" name="C1_<%=i%>" id="chk_<%=i%>"
    <% if cartArray(13,i)<>0 then reasponse.write " checked" %>>
    <% next %>

    > <% for i = 0 to Session("cartMaxUsed")
    > if request("C1_" & i) = "ON" then


    This is dangerous using the default request object.
    decide if your form is using method='post' or not.

    > cartArray(13,i) = 1


    Just entering true or false in the array
    is also the more logical way to go.

    > else
    > cartArray(13,i) = 0
    > end if


    <%
    for i = 0 to Session("cartMaxUsed")
    cartArray(13,i) = request.form("C1_" & i) <> ""
    next
    %>

    If you need the boolean array value later, just do:

    <%
    if cartArray(13,5) then ....
    %>

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Aug 9, 2007
    #5
  6. sjsean

    Rob ^_^ Guest

    Hi Evertjan,
    np. I do not intend to supply a solution, Only to butter the mind to
    explore. My code example was written on the top of my head, without the
    benefit of an IDE or a test plan.
    Regards.
    "Evertjan." <> wrote in message
    news:Xns99876507AB375eejj99@194.109.133.242...
    > Rob ^_^ wrote on 09 aug 2007 in microsoft.public.inetserver.asp.general:
    >
    >> <% for i = 0 to Session("cartMaxUsed")
    >> if cartArray(13,i)=0 then
    >> %>
    >> <input type="checkbox" name="C1_<%=i%>" " id="chk_<%=i%>" value="ON">
    >> <% else %>
    >>
    >> <input type="checkbox" name="C1_<%=i%>" " id="chk_<%=i%>" value="ON"
    >> checked>
    >> <% end if %>

    >
    > What does that extra " afer the name=".." do???
    >
    > I would not use the value="ON" of it is not checked.
    > I would not use a set value at all, since "on" is default,
    > and testing for empty string for not-checked is even simpler.
    >
    > It can be done more easily like this:
    >
    > <% for i = 0 to Session("cartMaxUsed") %>
    > <input type="checkbox" name="C1_<%=i%>" id="chk_<%=i%>"
    > <% if cartArray(13,i)<>0 then reasponse.write " checked" %>>
    > <% next %>
    >
    >> <% for i = 0 to Session("cartMaxUsed")
    >> if request("C1_" & i) = "ON" then

    >
    > This is dangerous using the default request object.
    > decide if your form is using method='post' or not.
    >
    >> cartArray(13,i) = 1

    >
    > Just entering true or false in the array
    > is also the more logical way to go.
    >
    >> else
    >> cartArray(13,i) = 0
    >> end if

    >
    > <%
    > for i = 0 to Session("cartMaxUsed")
    > cartArray(13,i) = request.form("C1_" & i) <> ""
    > next
    > %>
    >
    > If you need the boolean array value later, just do:
    >
    > <%
    > if cartArray(13,5) then ....
    > %>
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress)
     
    Rob ^_^, Aug 9, 2007
    #6
  7. sjsean

    Evertjan. Guest

    Rob ^_^ wrote on 09 aug 2007 in microsoft.public.inetserver.asp.general:

    > "Evertjan." <> wrote in message
    > news:Xns99876507AB375eejj99@194.109.133.242...
    >> Rob ^_^ wrote on 09 aug 2007 in microsoft.public.inetserver.asp.general:
    >>
    >>> <% for i = 0 to Session("cartMaxUsed")
    >>> if cartArray(13,i)=0 then
    >>> %>
    >>> <input type="checkbox" name="C1_<%=i%>" " id="chk_<%=i%>" value="ON">
    >>> <% else %>
    >>>
    >>> <input type="checkbox" name="C1_<%=i%>" " id="chk_<%=i%>" value="ON"
    >>> checked>
    >>> <% end if %>

    >>
    >> What does that extra " afer the name=".." do???
    >>
    >> I would not use the value="ON" of it is not checked.
    >> I would not use a set value at all, since "on" is default,
    >> and testing for empty string for not-checked is even simpler.
    >>
    >> It can be done more easily like this:
    >>
    >> <% for i = 0 to Session("cartMaxUsed") %>
    >> <input type="checkbox" name="C1_<%=i%>" id="chk_<%=i%>"
    >> <% if cartArray(13,i)<>0 then reasponse.write " checked" %>>
    >> <% next %>
    >>
    >>> <% for i = 0 to Session("cartMaxUsed")
    >>> if request("C1_" & i) = "ON" then

    >>
    >> This is dangerous using the default request object.
    >> decide if your form is using method='post' or not.
    >>
    >>> cartArray(13,i) = 1

    >>
    >> Just entering true or false in the array
    >> is also the more logical way to go.
    >>
    >>> else
    >>> cartArray(13,i) = 0
    >>> end if

    >>
    >> <%
    >> for i = 0 to Session("cartMaxUsed")
    >> cartArray(13,i) = request.form("C1_" & i) <> ""
    >> next
    >> %>
    >>
    >> If you need the boolean array value later, just do:
    >>
    >> <%
    >> if cartArray(13,5) then ....
    >> %>


    > Hi Evertjan,
    > np.


    ??

    > I do not intend to supply a solution, Only to butter the mind to
    > explore. My code example was written on the top of my head, without the
    > benefit of an IDE or a test plan.


    My posting was not ment to critisize your action,
    only to improve on some code, as I see it.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Aug 9, 2007
    #7
  8. "Evertjan." wrote:
    > I would not use the value="ON" of it is not checked.
    > I would not use a set value at all, since "on" is default,
    > and testing for empty string for not-checked is even simpler.


    Even more to the point, you can examine Request.Form(ElementName).Count.
    This is especially graceful in JScript:

    if (Request.Form(ElementName).Count) ... // it is checked


    --
    Dave Anderson

    Unsolicited commercial email will be read at a cost of $500 per message. Use
    of this email address implies consent to these terms.
     
    Dave Anderson, Aug 9, 2007
    #8
  9. sjsean

    vicky Guest

    Hi sjsean,

    You can use Ajax for this.
    when you click on a checkbox, call a asp page in background, that will
    update the session variable and will return you the string or XML
    file.

    In this way you will not need to reload the page each time you update
    something.

    sjsean wrote:
    > I've written an asp page in order to handle an array for a simple
    > shopping cart. What I am trying to accomplish is "deleting" one or
    > more of the items by basically setting one of the array values to 0 so
    > that the item won't be considered for further use. I've been
    > successful in determining which checkboxes are checked but it seems
    > that my code will set all the items to zero because my conditional
    > statement isn't working as I expect. Any suggestions are appreciated.
    >
    > <script type="text/vbscript">
    >
    > sub refresh()
    >
    >
    > <% for i = 0 to Session("cartMaxUsed")%>
    > if document.getElementById(i).checked = True then
    > <% cartArray(13,i)=0 %>
    > end if
    > <%next%>
    >
    > <%session("cartArray")=cartArray%>
    >
    > end sub
    >
    >
    >
    > </script>
     
    vicky, Aug 17, 2007
    #9
    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. Oscar
    Replies:
    3
    Views:
    6,477
    Steve C. Orr [MVP, MCSD]
    Oct 1, 2006
  2. Bill Rowell

    web user control invoking subroutine in parent page

    Bill Rowell, Nov 10, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    162
    Bill Rowell
    Nov 10, 2005
  3. Dan Burke
    Replies:
    6
    Views:
    276
    Dan Burke
    Jul 5, 2004
  4. king
    Replies:
    5
    Views:
    210
  5. Replies:
    0
    Views:
    184
Loading...

Share This Page