Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > subroutine issue in asp page

Reply
Thread Tools

subroutine issue in asp page

 
 
sjsean
Guest
Posts: n/a
 
      08-08-2007
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>

 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      08-08-2007
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)
 
Reply With Quote
 
 
 
 
sjsean
Guest
Posts: n/a
 
      08-09-2007
On Aug 8, 1:15 am, "Evertjan." <exjxw.hannivo...@interxnl.net> 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.

 
Reply With Quote
 
Rob ^_^
Guest
Posts: n/a
 
      08-09-2007
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: oups.com...
> On Aug 8, 1:15 am, "Evertjan." <exjxw.hannivo...@interxnl.net> 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.
>



 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      08-09-2007
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)
 
Reply With Quote
 
Rob ^_^
Guest
Posts: n/a
 
      08-09-2007
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)



 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      08-09-2007
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)
 
Reply With Quote
 
Dave Anderson
Guest
Posts: n/a
 
      08-09-2007
"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.

 
Reply With Quote
 
vicky
Guest
Posts: n/a
 
      08-17-2007
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>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CSPEC issue: lossing scope (or incorrect scope) in cspec subroutine. balldarrens@gmail.com Perl Misc 0 02-05-2009 08:42 PM
use one subroutine's variable value in another subroutine inside a module. king Perl Misc 5 04-29-2007 06:39 AM
How to load another aspx page within a VB subroutine? Oscar ASP .Net 3 10-01-2006 01:12 AM
web user control invoking subroutine in parent page Bill Rowell ASP .Net Web Controls 1 11-10-2005 08:00 PM
undefined subroutine that is defined? mob_perl / perl 5.8.4 issue? Dan Burke Perl Misc 6 07-04-2004 11:42 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57