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 with MSIE
plus

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

Check a Radio Button on Web Page


Question:

I have been looking through all possible examples in the Tech Data Base with no luck on finding a way to select a Radio button in a webpage using IE 6 SP1. I have looked at a couple of examples that were created using IE 4, but many things have changed since then regarding objects and methods.

Does anyone have a script I can look through or just post a snippet? I am trying to auto complete a form that requires me to select 1 of 2 radio buttons. I have looked at MSDN regarding getAttributes and setAttributes, but I have had no luck in making it work.

Appreciate any help.

Answer:

Radio buttons use the .checked property, so you just need to find the correct one and set the .checked property to @true or 1

This example looks to see which radio buttons are checked...

:QueryRadioButtons

RButtons = browserdoc.GetElementsbyTagname("INPUT")
For rb = 0 To RButtons.length-1
   thisbutton = RButtons.item(rb)
   If thisbutton.checked Then chainnumber = rb+1
   ObjectClose(thisbutton)
Next
ObjectClose(RButtons)
Return


Here's a better example...


#DefineSubRoutine startMSIE(url)
   Browser = ObjectOpen("InternetExplorer.Application")
   Browser.addressbar = @FALSE
   Browser.statusbar = @FALSE
   Browser.menubar = @FALSE
   Browser.toolbar = @FALSE
   browser.visible = @TRUE
   browser.navigate(url)
   ; wait until page loads...
   WaitForPageLoad()
   ; setup the document object...
   browserDoc = Browser.Document
   all = browserdoc.all
   Return(browser)
#EndSubRoutine

#DefineSubroutine WaitForPageLoad()  ; assume Browser
   While browser.busy || browser.readystate == 1
      TimeDelay(0.5)
   EndWhile
   While browser.Document.ReadyState != "complete"
      TimeDelay(0.5)
   EndWhile
   return
#EndSubroutine




url = "C:\AnyOldURL.html"
RBNumbers = "1|2|3|4|5"

br = startMSIE(url)
GoSub writeFormattedTable1
RBtoCheck = AskItemlist("Radio Buttons", RBNumbers, "|", @SORTED, @SINGLE)

Message("Debug", StrCat("I will check button #", RBtoCheck))

GoSub CheckRadioButton
TimeDelay(5)                     ;<--- give user a few seconds to see button checked...
br.quit

Exit


:writeFormattedTable1

ThisVar = ""
ThisVar = StrCat(ThisVar, '<table class="blue coll" width="100%%" border="0" cellspacing="0" cellpadding="3" id="MenuDisplay">', @CRLF)
ThisVar = StrCat(ThisVar, `<tr><th bgcolor="powderblue">Categories</th></tr>`, @CRLF)
ThisVar = StrCat(ThisVar, '  <tr> ', @CRLF)
ThisVar = StrCat(ThisVar, '    <td> ', @CRLF)
ThisVar = StrCat(ThisVar, '      <div align="center" id="TopMenu"> </div>', @CRLF)
ThisVar = StrCat(ThisVar, '    </td>', @CRLF)
ThisVar = StrCat(ThisVar, '  </tr>', @CRLF)
ThisVar = StrCat(ThisVar, '  <tr> ', @CRLF)
ThisVar = StrCat(ThisVar, '    <td> ', @CRLF)
ThisVar = StrCat(ThisVar, '      <div align="center"> ', @CRLF)
ThisVar = StrCat(ThisVar, '        <table class="blue coll" width="50%%" border="0" cellspacing="0" cellpadding="0">', @CRLF)
ThisVar = StrCat(ThisVar, '          <tr> ', @CRLF)
ThisVar = StrCat(ThisVar, '            <td> ', @CRLF)
;ThisVar = strcat(ThisVar, '              <input type="radio" name="radiobutton" value="radiobutton" checked="yes">', @crlf)
ThisVar = StrCat(ThisVar, '              <input type="radio" name="radiobutton" value="radiobutton">', @CRLF)
ThisVar = StrCat(ThisVar, '              Chain 1</td>', @CRLF)
ThisVar = StrCat(ThisVar, '            <td> ', @CRLF)
ThisVar = StrCat(ThisVar, '              <input type="radio" name="radiobutton" value="radiobutton">', @CRLF)
ThisVar = StrCat(ThisVar, '              Chain 2</td>', @CRLF)
ThisVar = StrCat(ThisVar, '            <td> ', @CRLF)
ThisVar = StrCat(ThisVar, '              <input type="radio" name="radiobutton" value="radiobutton">', @CRLF)
ThisVar = StrCat(ThisVar, '              Chain 3</td>', @CRLF)
ThisVar = StrCat(ThisVar, '            <td> ', @CRLF)
ThisVar = StrCat(ThisVar, '              <input type="radio" name="radiobutton" value="radiobutton">', @CRLF)
ThisVar = StrCat(ThisVar, '              Chain 4</td>', @CRLF)
ThisVar = StrCat(ThisVar, '            <td> ', @CRLF)
ThisVar = StrCat(ThisVar, '              <input type="radio" name="radiobutton" value="radiobutton">', @CRLF)
ThisVar = StrCat(ThisVar, '              Chain 5</td>', @CRLF)
ThisVar = StrCat(ThisVar, '          </tr>', @CRLF)
ThisVar = StrCat(ThisVar, '        </table>', @CRLF)
ThisVar = StrCat(ThisVar, '      </div>', @CRLF)
ThisVar = StrCat(ThisVar, '    </td>', @CRLF)
ThisVar = StrCat(ThisVar, '  </tr>', @CRLF)
ThisVar = StrCat(ThisVar, '</table>', @CRLF)

browserdoc.writeln(ThisVar)

Return

:QueryRadioButtons

RButtons = browserdoc.GetElementsbyTagname("INPUT")
For rb = 0 To RButtons.length-1
   thisbutton = RButtons.item(rb)
   If thisbutton.checked Then chainnumber = rb+1
   ObjectClose(thisbutton)
Next
ObjectClose(RButtons)
Return

:CheckRadioButton
RButtons = browserdoc.GetElementsbyTagname("INPUT")
thisbutton = RButtons.item(RBtoCheck-1)               ;<--- zero based so subtract 1...
thisbutton.checked = @TRUE
ObjectClose(thisbutton)
ObjectClose(RButtons)
Return

Article ID:   W16111
File Created: 2004:08:02:10:35:38
Last Updated: 2004:08:02:10:35:38