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 2089 jhardman 3,406
Recognized Expert Specialist
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
jhardman 3,406
Recognized Expert Specialist
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
jhardman 3,406
Recognized Expert Specialist
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
jhardman 3,406
Recognized Expert Specialist
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 checkboxes are picked up using $_POST and put into session
variables. On page two there is another form which is simply a
condensed version 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" id="id_number" name="check" value="2"
onclick="show()"/>
<input type="checkbox" id="id_number" name="check" value="3"
|
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 System.Windows.Forms.ListView. Among
other features, it enables the checkboxes and overrides the OnItemCheck()
method. I have placed this ListView on a form and...
|
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 up. As long as none of the checkboxes are
disabled, viewstate works fine - and client actions are 'remembered' after a
postback. but when I have...
|
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 of chkboxes categorized as flowers. How can i display all the checked items to only one page?
Pls. give me idea. thanks.
| |
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:
I dynamically add an htmlcheckbox to a webform in the pages render and set
the checked value to true. When the page loads, if I remove the check...
|
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
javascript ) and
checked checkboxes text will be concat and that string will be pass on
to report query
I m trying on by this code but it's not work
|
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 do $_POST.
But what to do in that situation ?
Sincerely,
Dmitrij
|
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;?>">
First Name:<input type="text" size="12" maxlength="12" name="Fname"><br >
Last Name:<input type="text" size="12" maxlength="36" name="Lname"><br />...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |