WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE COM ADO CDO ADSI LDAP
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

ObjectEventAdd Issue

 Keywords:  

Question:

I'm trying to have a Winbatch UDS turn the background of the checkbox and the prior/subsequent Table element to a different color once a checkbox is checked (and back to white) if it's unchecked. However I see the box is clicked and which one registers with the script but the box doesn't actually show as checked on the screen. Why is this?

Here is the code is am using:

CBTEST.HTML

<HTML><HEAD></HEAD>
<BODY>
<TABLE align=center border=0>
<TBODY>
<TR>
<TD vAlign=top>
<TABLE class="bigblue frame" id=Table1 style="FONT-SIZE: 7pt; BORDER-COLLAPSE: collapse" cellPadding=2 border=1>
<TBODY>
<TR>
<TD id=Cat1 style="FONT-SIZE: 9pt">Item #1</TD>
<TD><INPUT id=CB1 type=checkbox name=checker></TD>
<TD><INPUT class=bigblue id=RTMMDBox1 style="WIDTH: 7mm; TEXT-ALIGN: center" size=5 value=0 name=number></TD></TR>
<TR>
<TD id=Cat2 style="FONT-SIZE: 9pt">Item #2</TD>
<TD><INPUT id=CB2 type=checkbox name=checker></TD>
<TD><INPUT class=bigblue id=RTMMDBox2 style="WIDTH: 7mm; TEXT-ALIGN: center" size=5 value=0 name=number></TD></TR>
<TR>
<TD id=Cat3 style="FONT-SIZE: 9pt">Item #3</TD>
<TD><INPUT id=CB3 type=checkbox name=checker></TD>
<TD><INPUT class=bigblue id=RTMMDBox3 style="WIDTH: 7mm; TEXT-ALIGN: center" size=5 value=0 name=number></TD></TR>
<TR>
<TD id=Cat4 style="FONT-SIZE: 9pt">Item #4</TD>
<TD><INPUT id=CB4 type=checkbox name=checker></TD>
<TD><INPUT class=bigblue id=RTMMDBox4 style="WIDTH: 7mm; TEXT-ALIGN: center" size=5 value=0 name=number></TD></TR>
</TBODY></TABLE></TD></TR></TBODY></TABLE>
<CENTER><INPUT id=DoneButton style="margin-top: 10mm" type=submit value=Done></CENTER></BODY></HTML>

CBTEST.WBT


#DefineFunction startMSIE(url)
   msie = ObjectCreate("InternetExplorer.Application")
   msie.visible = @TRUE
   msie.navigate(url)
   WaitForMSIE(msie)
   Return(msie)
#EndFunction

#DefineFunction WaitForMSIE(msie)
   While msie.busy || msie.readystate <> 4
      TimeDelay(0.5)
   EndWhile
   Return
#EndFunction

#DefineSubRoutine CloseMSIE()
   Exit
   Return
#EndSubRoutine

#DefineSubRoutine ExitScript()
   loop = @FALSE
   Return
#EndSubRoutine

#DefineSubRoutine BodyClick()
   Element = br.document.parentWindow.event.srcElement
   If Element.TagName == "INPUT"
   If Element.name == "checker"
      Message("Debug", Element.checked)
      If Element.checked == -1
         color = "palegreen"
         Element.checked = 1
      Else
         color = "white"
      EndIf
      Element.parentNode.style.backgroundColor = color
      Element.parentNode.previousSibling.style.backgroundColor = color
      Element.parentNode.nextSibling.style.backgroundColor = color
   EndIf
   Element = 0
   EndIf
   Return
#EndSubRoutine


hfile = StrCat(DirScript(), "CBTest.html")
br = startMSIE(hfile)
iC = br.document.getElementsByName("checker")
cbArray = ArrDimension(iC.length)
ArrInitialize(cbArray, 0)
For x = 0 To ArrInfo(cbArray, 1)-1
   cbArray[x] = iC.item(x)
Next
For x = 0 To ArrInfo(cbArray, 1)-1
   ObjectEventAdd(cbArray[x], "onclick", "BodyClick")
Next
db = br.document.getElementById("DoneButton")
ObjectEventAdd(db, "onclick", "ExitScript")
dbr = br
ObjectEventAdd(dbr, "onquit", "CloseMSIE")
loop = @TRUE
While loop
   TimeDelay(-0.1)
EndWhile
br.quit
Exit

Answer:

The meaning of the event handler's Return value must always be considered. Try "return @True" at the end of the event handler UDS. See line marked by ;!!!!!!!!!


#DefineFunction startMSIE(url)
   msie = ObjectCreate("InternetExplorer.Application")
   msie.visible = @TRUE
   msie.navigate(url)
   WaitForMSIE(msie)
   Return(msie)
#EndFunction

#DefineFunction WaitForMSIE(msie)
   While msie.busy || msie.readystate <> 4
      TimeDelay(0.5)
   EndWhile
   Return
#EndFunction

#DefineSubRoutine CloseMSIE()
   Exit
   Return
#EndSubRoutine

#DefineSubRoutine ExitScript()
   loop = @FALSE
   Return
#EndSubRoutine

#DefineSubRoutine BodyClick()
   Element = br.document.parentWindow.event.srcElement
   If Element.TagName == "INPUT"
   If Element.name == "checker"
      Message("Debug", Element.checked)
      If Element.checked == -1
         color = "palegreen"
         Element.checked = 1
      Else
         color = "white"
      EndIf
      Element.parentNode.style.backgroundColor = color
      Element.parentNode.previousSibling.style.backgroundColor = color
      Element.parentNode.nextSibling.style.backgroundColor = color
   EndIf
   Element = 0
   EndIf
   Return @TRUE ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#EndSubRoutine


hfile = StrCat(DirScript(), "CBTest.html")
br = startMSIE(hfile)
iC = br.document.getElementsByName("checker")
cbArray = ArrDimension(iC.length)
ArrInitialize(cbArray, 0)
For x = 0 To ArrInfo(cbArray, 1)-1
   cbArray[x] = iC.item(x)
Next
For x = 0 To ArrInfo(cbArray, 1)-1
   ObjectEventAdd(cbArray[x], "onclick", "BodyClick")
Next
db = br.document.getElementById("DoneButton")
ObjectEventAdd(db, "onclick", "ExitScript")
dbr = br
ObjectEventAdd(dbr, "onquit", "CloseMSIE")
loop = @TRUE
While loop
   TimeDelay(-0.1)
EndWhile
br.quit
Exit

Article ID:   W17095
File Created: 2007:07:03:14:28:16
Last Updated: 2007:07:03:14:28:16