Hi all,
This is my first post so please bear with me.
I have a youth soccer uniform order ASP application that loads and pulls from a SQL database that allows soccer teams to construct a uniform kit.
Each piece of the uniform kit can come in a possible 14 different sizes. But some may only come in 12, 6, 3 sizes or whatever.
So when the team uniform guy Creates the kit he checks what sizes are available for each jersey, shorts, socks, etc.
So I set up 14 checkboxes for each Item of clothing on the Kit creation form. (And a kit update page) These are single named sets of check boxes like “KitJersey1Size”
The problem comes with the kit update page; I would like to display all the checkboxes that were checked in the Kit creation form as "Checked" and allow the sizes checked to be changed. And display the checkboxs as"unchecked" if they were not checked originally.
My solution is to create an array of the listed sizes from the data base and then create an array of all the possible 14 sizes. Then nest two for loops to check if the size exists if it does write a checked checkbox, if not write an unchecked checkbox.
My problem is that I can’t get my head around the VBScript syntax for this brilliant idea of mine. Also this may not be the most elegant solution; I strive to write KISS code whenever possible. Am I all wet or what?
So please any help would be really appreciated.
Thanks in advance
Dave
9 2079
Dave,
This sounds like a perfectly valid approach, the difficult step here is generally to think up how is the data of "all possible sizes" stored and how is the data of "sizes selected" stored, and how can we get the two to jive. So let me ask, what will these two data sets look like at this point? If you wanted to just print out a list of every size available and every size selected (don't worry yet about making it look good), how would the code look?
Jared
Hi Jared,
Thanks for replying
To print out the 2 sets of sizes
I would: -
'All Sizes array
-
AllADSize = "Adult2XS, AdultXS, AdultS, AdultM, AdultLG, AdultXL, Adult2XL"
-
ArrAllADSize = split(AllADSize,", ")
-
-
'Selected Sizes array from DB
-
AllJS1 = (rs2("KitJersey1Size"))
-
arrJ1Size = split(AllJS1,", ")
-
-
-
for j = 0 to unbound(ArrAllADSize)
-
response.Write " AllSizes= " & ArrAllADSize(j) &"<BR>"
-
-
next
-
-
'and
-
-
for i = 0 to ubound(arrJ1Size)
-
response.Write " SizesSelected = " & arrJ1Size(j) &"<BR>"
-
next
-
-
Here is the code I am currently trying: -
'Selected Sizes array from DB
-
-
AllJS1 = (rs2("KitJersey1Size"))
-
'response.Write("AllJS1 = " & AllJS1)
-
arrJ1Size = split(AllJS1,", ")
-
-
'All sizes array
-
-
AllADSize = "Adult2XS, AdultXS, AdultS, AdultM, AdultLG, AdultXL, Adult2XL"
-
'response.Write("AllADSize = " & AllADSize)
-
ArrAllADSize = split(AllADSize,", ")
-
-
-
'Outer loop of "all sizes"
-
-
for j = 0 to unbound(ArrAllADSize)
-
'response.Write " 1st Loop = " '& ArrAllADSize(j)
-
-
'Inner loop of sizes from data base
-
-
for i = 0 to ubound(arrJ1Size)
-
if arrJ1Size(i) <> ArrAllADSize(j) then
-
-
%>
-
-
<%=arrJ1Size(i)%><input type="checkbox" name="KitJersey1Size" value="" class="smallplaintext">
-
-
-
-
<%
-
exit for
-
-
elseif arrJ1Size(i) = ArrAllADSize(j) then
-
-
%>
-
-
-
<%=arrJ1Size(i)%><input type="checkbox" name="KitJersey1Size" value="<%=arrJ1Size(i)%>" class="smallplaintext" checked="checked">
-
-
<%
-
-
end if
-
Next
-
-
Next
-
-
%>
-
Thanks again
I just can't seem to get my head around the syntax of these two loops
Dave
Hi Jared,
Thanks for replying
To print out the 2 sets of sizes
I would: -
'All Sizes array
-
AllADSize = "Adult2XS, AdultXS, AdultS, AdultM, AdultLG, AdultXL, Adult2XL"
-
ArrAllADSize = split(AllADSize,", ")
-
-
'Selected Sizes array from DB
-
AllJS1 = (rs2("KitJersey1Size"))
-
arrJ1Size = split(AllJS1,", ")
-
-
-
for j = 0 to unbound(ArrAllADSize)
-
response.Write " AllSizes= " & ArrAllADSize(j) &"<BR>"
-
-
next
-
-
'and
-
-
for i = 0 to ubound(arrJ1Size)
-
response.Write " SizesSelected = " & arrJ1Size(j) &"<BR>"
-
next
Are the two lists necessarily in the same order? I mean the list of all sizes might be "AA, BB, CC, DD" and the selected list might be "BB, DD" and definitely not "DD, CC".
Jared
Hmm... Interesting question,
The all sizes array should be in order because it was loaded in order. I suppose I could load it like this: -
ArrAllADSize(0) = Adult2XS
-
ArrAllADSize(1) = AdultXS
-
etc.
To be sure of the order.
But I get your point that arrJ1Size() (from the db) could be in the same order but most likely will be missing some elements listed in ArrAllADSize().
My thought was that by using the two loops I would run a comparison with the first element of ArrAllADSize(0-14) with each of the elements in arrJ1Size(0-?) to find a match or not then loop to ArrAllADSize(1) and compare again with each of the elements in arrJ1Size(0-?) and so on...
Since I am comparing all the elements in arrJ1Size(0-?) with each element in ArrAllADSize() would the order matter?
Either Adult2XS (ArrAllADSize(0)) exists in arrJ1Size() or it doesn’t, and so on. Or am I missing something here?
Thanks
Dave
As to the data stored question here is what happend when I printed out both arrays
Here is the allsizes array printout:
AllSizes= Adult2XS
AllSizes= AdultXS
AllSizes= AdultSM
AllSizes= AdultMED
AllSizes= AdultLG
AllSizes= AdultXL
AllSizes= Adult2XL
AllSizes= Youth2XS
AllSizes= YouthXS
AllSizes= YouthSM
AllSizes= YouthMED
AllSizes= YouthLG
AllSizes= YouthXL
AllSizes= Youth2XL
From the database:
AllJS1 = Adult2XS, AdultXS, AdultSM, AdultMED, AdultLG, AdultXL, Adult2XL, Youth2XS, YouthXS, YouthSM, YouthMED, YouthLG, YouthXL, Youth2XL
Then the array printout
SizesSelected = Adult2XS
SizesSelected = AdultXS
SizesSelected = AdultSM
SizesSelected = AdultMED
SizesSelected = AdultLG
SizesSelected = AdultXL
SizesSelected = Adult2XL
SizesSelected = Youth2XS
SizesSelected = YouthXS
SizesSelected = YouthSM
SizesSelected = YouthMED
SizesSelected = YouthLG
SizesSelected = YouthXL
SizesSelected = Youth2XL
this looks good to me
Dave
My thought was that by using the two loops I would run a comparison with the first element of ArrAllADSize(0-14) with each of the elements in arrJ1Size(0-?) to find a match or not then loop to ArrAllADSize(1) and compare again with each of the elements in arrJ1Size(0-?) and so on...
Since I am comparing all the elements in arrJ1Size(0-?) with each element in ArrAllADSize() would the order matter?
Either Adult2XS (ArrAllADSize(0)) exists in arrJ1Size() or it doesn’t, and so on. Or am I missing something here?
Thanks
Dave
You could definitely do it that way, and that might be better than what I was going to suggest. I was going to say loop through the bigger list once. within the big list, advance through smaller list only if you get a match: -
for x = 0 to ubound(biglist)
-
if biglist(x) = smallList(i) then
-
'print out a checked box
-
i = i + 1
-
else
-
'print out an un-checked box
-
end if
-
next
If it is a hundred percent guaranteed that they will be in the same order this will work just fine. Otherwise, your solution would be preferred.
Jared
You could definitely do it that way, and that might be better than what I was going to suggest. I was going to say loop through the bigger list once. within the big list, advance through smaller list only if you get a match: -
for x = 0 to ubound(biglist)
-
if biglist(x) = smallList(i) then
-
'print out a checked box
-
i = i + 1
-
else
-
'print out an un-checked box
-
end if
-
next
If it is a hundred percent guaranteed that they will be in the same order this will work just fine. Otherwise, your solution would be preferred.
Jared
My method is all well and good but I can't get it to work.
I don't know what I am doing wrong. "exit for" in the wrong place??? I'm stumped
Here is the latest attempt: -
for j = 0 to ubound(ArrAllADSize)
-
'response.Write " 1st Loop = " & ArrAllADSize(j)
-
-
for i = 0 to ubound(arrJ1Size)
-
if arrJ1Size(i) = ArrAllADSize(j) then
-
'response.Write " 2nd Loop = " & arrJ1Size(1)
-
%>
-
<%=ArrAllADSize(j)%><input type="checkbox" name="KitJersey1Size" value="<%=ArrAllADSize(j)%>" class="smallplaintext" checked="checked">
-
-
-
<% exit for
-
'next
-
elseif arrJ1Size(i) <> ArrAllADSize(j) then
-
%>
-
<%=ArrAllADSize(j)%><input type="checkbox" name="KitJersey1Size" value="" class="smallplaintext">
-
-
<%
-
end if
-
Exit for
-
Next
-
-
Next
-
-
-
%>
-
when I run this I get all the checkboxes printed.
In this instance all the sizes are the same in both arrays so all the checkboxes printed should be checked. What I get is the first checkbox is printed and is checked, then all the other checkboxes are printed but, are not checked as they should be.
It's like the first loop fires once then and the test works. Then for some reason the test fails. Is the first loop stoping after the first itteration? I don't know.
Thanks
Dave
Dave,
Whenever you use an "exit for" there is quaranteed to be a better solution. Try it more like this: -
for j = 0 to ubound(ArrAllADSize)
-
addedText = ""
-
'response.Write " 1st Loop = " & ArrAllADSize(j)
-
-
for i = 0 to ubound(arrJ1Size)
-
if arrJ1Size(i) = ArrAllADSize(j) then
-
addedText = " checked=" & chr(34) & "checked" & chr(34)
-
end if
-
next %>
-
<%=ArrAllADSize(j)%><input type="checkbox" name="KitJersey1Size" value="<%=ArrAllADSize(j)%>" class="smallplaintext" <%=addedText%>>
-
<%
-
next %>
Your "exit for" lines were second guessing you, the inner loop was never moving, it ran through the loop once then exited. If the first value was the same you got a "checked" box, otherwise you always got a "unchecked" box.
Let me know if this helps.
Jared
Hi Jared,
Thanks so much that works perfectly!
I think it is a typical case of me trying to make things more complicated than they need to be. I just couldn't see what I was doing wrong. Thanks again
this is a great group
Dave
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Pete |
last post by:
There is a Summary/Example further down...
On page one of my site I have a form with some checkboxes and detailed
descriptions. When the form is submitted (to page two), the values of
the...
|
by: Piotr |
last post by:
how can I read (in alert for example) array index number of checked
checkbox?
I have:
<input type="checkbox" id="id_number" name="check" value="1"
onclick="show()"/>
<input type="checkbox"...
|
by: Aaron Queenan |
last post by:
Is there any way to know whether the OnItemCheck is being called in response
to a user action (mouse or keyboard) as opposed to the form loading?
I have a class which derives from...
|
by: RodBillett |
last post by:
I have a situation where I have 3 checkboxes - and at least 1 needs to be
selected at all times...
I have implemented the code that allows this behavior to happen, BUT
Viewstate gets all messed...
|
by: kit7kat |
last post by:
hi there,
do u have any idea how i can display the names of checkboxes checked from different webpages. Say one page has a list of checkboxes categorized are fruits. Then another page has list...
|
by: Kevin R |
last post by:
This is one of the weirdest problems I have ever run into. I have had to
trim down a bunch of code to give a sample that is more easily readable by
those who will view this. Here is the problem:...
|
by: haresh.amis |
last post by:
hello to all,
I m using .net 2.0 and i face a problem that is as under
Well I have a checkboxlist which i bound in .cs page
now I want to count that how many checkboxes ate checked ( In...
|
by: dkultasev |
last post by:
Hello,
I have small script which generates some listboxes. Their names are
listXX (list01, list02, list03....). How to check if there are checked
or not ? If I have 1 listbox and have it's name I...
|
by: dba |
last post by:
Have been displaying data from database using html for some time but
just recently trying to display data back to "form". Can't find answer.
<form method="post" action="<?php echo $PHP_SELF;?>">...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |