subroutine issue in asp page

S

sjsean

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>
 
E

Evertjan.

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.
 
S

sjsean

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%>

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.

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.
 
R

Rob ^_^

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 said:
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%>

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.

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.
 
E

Evertjan.

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" %>>
<% 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 ....
%>
 
R

Rob ^_^

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.
 
E

Evertjan.

Rob ^_^ wrote on 09 aug 2007 in microsoft.public.inetserver.asp.general:
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.
 
D

Dave Anderson

Evertjan. said:
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
 
V

vicky

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top