Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

HTA application, looping through checkboxes nightmare.

651 views
Skip to first unread message

jimmyjones

unread,
Apr 15, 2013, 8:43:28 AM4/15/13
to
How can I get this to work?

strWhatsChecked = ""
intForLoopCounter = 0
Set CBForm = Document.ChkBoxFrm
' intNumberOfCheckBoxesInForm = document.ChkBoxFrm.ChkBoxThing.length
intNumberOfCheckBoxesInForm = CBForm.ChkBoxThing.length
MsgBox "Number of Check boxes in the form = " &
intNumberOfCheckBoxesInForm

For intForLoopCounter = 1 to intNumberOfCheckBoxesInForm
strForLoopCounterValue = chr(Cint(intForLoopCounter+48))
MsgBox "intForLoopCounter = " & intForLoopCounter & VbCrLf &
"integer to string :" & strForLoopCounterValue
If document.ChkBoxFrm.ChkBox & strForLoopCounterValue.Checked Then
strWhatsChecked = CBForm.ChkBox & strForLoopCounterValue.Value
& " "
End If

Next


I get the number of checkboxes returned correctly, but when trying to iterate
through these checkboxes, I get this error at the IF statement.

�Object required: �strForLoopCounterValue�.




--
--------------------------------- --- -- -
Posted with NewsLeecher v5.2 Beta 2
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

Mayayana

unread,
Apr 15, 2013, 9:19:02 AM4/15/13
to
You're using strForLoopCounterValue as both a string and a checkbox. There's no way to tell the exact error, since you didn't post the full code, but it looks like these... strForLoopCounterValue.Checked strForLoopCounterValue.Value ...are mistakes. Near the end it gets more mixed up: strWhatsChecked = CBForm.ChkBox & strForLoopCounterValue.Value You seem to be assigning a checkbox to a string, along with strForLoopCounterValue.Value, the "value" of a string that's been reused as a checkbox. If you don't work it out you might want to post more of the actual code. I also wonder why you seem to be trying to submit form data from an HTA. Why wouldn't you process the data in your own script? (If ChkBox.checked = True then...) Maybe there's some logic there that I've overlooked, but I can't think of where one might submit the form data to from inside an HTA, since an HTA has to run locally. "jimmyjones" <jimmy...@gmx.com> wrote in message news:516bf5f0$0$10618$c3e8da3$b667...@news.astraweb.com... | How can I get this to work? | strWhatsChecked = "" | intForLoopCounter = 0 | Set CBForm = Document.ChkBoxFrm | ' intNumberOfCheckBoxesInForm = document.ChkBoxFrm.ChkBoxThing.length | intNumberOfCheckBoxesInForm = CBForm.ChkBoxThing.length | MsgBox "Number of Check boxes in the form = " & | intNumberOfCheckBoxesInForm | For intForLoopCounter = 1 to intNumberOfCheckBoxesInForm | strForLoopCounterValue = chr(Cint(intForLoopCounter+48)) | MsgBox "intForLoopCounter = " & intForLoopCounter & VbCrLf & | "integer to string :" & strForLoopCounterValue | If document.ChkBoxFrm.ChkBox & strForLoopCounterValue.Checked Then | strWhatsChecked = CBForm.ChkBox & strForLoopCounterValue.Value | & " " | End If | Next | I get the number of checkboxes returned correctly, but when trying to iterate | through these checkboxes, I get this error at the IF statement. Object required: strForLoopCounterValue

jimmyjones

unread,
Apr 15, 2013, 9:51:53 AM4/15/13
to
I have a lot of checkboxes in a form, and the number of these checkboxes may change from one computer to another.

I am trying to get how many checkboxes there are in the form, and then iterate through each checkbox to see if it is checked, and if so, append the value of it onto the end of a string, which I will later split for further processing.

I know I am trying to add a string to an object but I don't know how else to loop through these checkboxes.

I have already did it this way (If ChkBox.checked = True then...), and while it is good if I know how many checkboxes there are in the form, I have to change the number of IF statements if the number if checkboxes changes.

Thanks for your help.


On Monday, April 15, 2013 2:19:02 PM UTC+1, Mayayana wrote:
> You're using strForLoopCounterValue as both a string
>
> and a checkbox. There's no way to tell the exact error,
>
> since you didn't post the full code, but it looks like these...
>
>
>
> strForLoopCounterValue.Checked
>
> strForLoopCounterValue.Value
>
>
>
> ...are mistakes. Near the end it gets more mixed up:
>
>
>
> strWhatsChecked = CBForm.ChkBox & strForLoopCounterValue.Value
>
>
>
> You seem to be assigning a checkbox to a string, along with
>
> strForLoopCounterValue.Value, the "value" of a string that's
>
> been reused as a checkbox.
>
>
>
> If you don't work it out you might want to post more
>
> of the actual code.
>
>
>
> I also wonder why you seem to be trying to submit form
>
> data from an HTA. Why wouldn't you process the data
>
> in your own script? (If ChkBox.checked = True then...)
>
> Maybe there's some logic there that I've overlooked, but
>
> I can't think of where one might submit the form data to
>
> from inside an HTA, since an HTA has to run locally.
>
>
>
> --
>
> --
> | Object required: strForLoopCounterValue .
>
> |

Mayayana

unread,
Apr 15, 2013, 10:09:55 AM4/15/13
to
I have a lot of checkboxes in a form, and the number of these checkboxes may
change from one computer to another.
---------------------------------

One way would be like this:

With document.all
For i = 0 to .length - 1
If .item(i).tagName = "INPUT" then
If .item(i).type = "checkbox" then
'collect value ofany relevant attribute here
' and check whether checkbox is checked.
End If
End If
Next
End With

I just used the With for a slight improvement in efficiency.
It's not required. Also, watch out for case. I think that
tag names always come through ucase. I'm not sure
about attribute values. Comparing strings with = isa
binary comparison, so if you want to play it safe you can
do something like this:

If UCase(.item(i).tagName) = "INPUT" then
If Ucase(.item(i).type) = "CHECKBOX" then


Dave "Crash" Dummy

unread,
Apr 15, 2013, 11:07:21 AM4/15/13
to
Life is simpler if the checkboxes of interest are all given the same name.
For example, <input type="checkbox" name="box" value="Alpha">
<input type="checkbox" name="box" value="Beta">
Then the number of boxes and their values are immediately available.

NumberOfBoxes=box.length
CheckedBoxes=""
for n=0 to NumberOfBoxes-1
if box(n).checked then CheckedBoxes=CheckedBoxes & box(n).value & vbCRLF
next

--
Crash

Today is the first day of the rest of your life,
and there's not a damned thing you can do about it.

Micky Love

unread,
Apr 15, 2013, 11:07:24 AM4/15/13
to
I don't know what the two IF statements do, but if I try to comment
out the first one(because I have no idea what a tagname is, the script
stops with error at the second IF statement.

Object doesn;t support this property or method: 'item(...).type'

Regards,

Micky Love

unread,
Apr 15, 2013, 11:23:36 AM4/15/13
to
I really gotta thank you both.
This worked a treat.
strWhatsChecked = ""
Set CBForm = Document.ChkBoxFrm
intNumberOfCheckBoxesInForm =
document.ChkBoxFrm.ChkBoxThing.length
MsgBox "Number of Check boxes in the form = " &
intNumberOfCheckBoxesInForm
For intForLoopCounter = 0 to intNumberOfCheckBoxesInForm - 1
If CBForm.ChkBox(intForLoopCounter).checked then
strWhatsChecked=strWhatsChecked &
CBForm.ChkBox(intForLoopCounter).value & vbCRLF
' msgBox strWhatsChecked
End If
Next

Thanks again.

Mayayana

unread,
Apr 15, 2013, 4:37:58 PM4/15/13
to
I don't know what the two IF statements do, but if I try to comment
out the first one(because I have no idea what a tagname is, the script
stops with error at the second IF statement.

Object doesn;t support this property or method: 'item(...).type'

------------------------------------

It sounds like you have it solved, but for future
reference, an Item in all (or in the "box" collection)
is an HTMLElement object. (An HTML tag.) You can
apply any properties that apply to the element. If
you don't have the IE DOM docs you should get
a copy. In it you can look up properties and methods.
One property common to all elements is tagName,
which is "B", "A", "DIV", etc.

So the first If in my sample checks whether the
current item is an INPUT tag. If so, it checks whether
the type is checkbox. The error is because when you
remove the check for INPUT, all items trigger the second
check. Since not all tags have a "type" property, an error
results when it reaches one that doesn't.

Another common use is for events. The example below
will show the tagName and ID for any item in the page
that the mouse hovers over, while also coloring that item
red. It then colors the item to white again when the mouse
leaves. The srcElement object is the HTML tag that triggered
event:

<HTML><HEAD>
<SCRIPT LANGUAGE="VBScript">
Sub document_onmouseover()
Label1.innerText = document.parentwindow.event.srcElement.tagname & " - " &
document.parentwindow.event.srcElement.ID
document.parentwindow.event.srcElement.style.backgroundcolor = "#FF0000"
End Sub
Sub document_onmouseout()
document.parentwindow.event.srcElement.style.backgroundcolor = "#FFFFFF"
End Sub
</SCRIPT>
</HEAD>
<BODY>
<B>bold text</B>
<DIV ID="Div1">divtext</DIV>
<P ID="p1">a paragraph</P>
<LABEL ID="Label1" STYLE="width: 200px; border-style: solid; border-color:
#AAAAAA;">
</BODY></HTML>




0 new messages