IE Automation - Radio Buttons (1 Viewer)

abbaddon223

Registered User.
Local time
Today, 02:19
Joined
Mar 13, 2010
Messages
162
Hello experts,

I'm trying to tick "Yes" to a radio button which are side by side on a web page (Yes and No). The HTML is below and the VBA I'm trying to use is:

ie.Document.all.Item("newsletter").Checked = "0"

I've also tried

ie.Document.all.Item("newsletter").Checked = "True"
ie.Document.all.Item("newsletter").value = "True"
ie.Document.all.Item("newsletter").value= "0"

<table class="form"> <tr> <td>Subscribe:</td> <td> <input type="radio" name="newsletter" value="1" /> Yes <input type="radio" name="newsletter" value="0" checked="checked" /> No </td> </tr> </table> </div>Any help would be greatly appreciated please. Thank you.

Phil.
 

pr2-eugin

Super Moderator
Local time
Today, 10:19
Joined
Nov 30, 2011
Messages
8,494
Sorry wrong method.. Give me a minute..
 
Last edited:

pr2-eugin

Super Moderator
Local time
Today, 10:19
Joined
Nov 30, 2011
Messages
8,494
Okay without an ID for the element you will not be able to check a particular Option, as the Radio button needs to be a common name, thus grouping them together in your case "newsletter", if you have something like..
Code:
<table class="form">
    <tr> 
        <td>Subscribe:</td> 
        <td> 
            <input type="radio" name="newsletter" value="1" [COLOR=Blue][B]id="yes"[/B][/COLOR] /> Yes 
            <input type="radio" name="newsletter" value="0" [COLOR=Blue][B]id="no"[/B][/COLOR] checked="checked" /> No 
        </td> 
    </tr> 
</table>
Then you can use..
Code:
document.getElementById('yes').checked = true;
 

abbaddon223

Registered User.
Local time
Today, 02:19
Joined
Mar 13, 2010
Messages
162
Hi again Pr2-eugin - thanks for the help once more!!

Your last gave me an Object Required error - but I note your point above...
 

abbaddon223

Registered User.
Local time
Today, 02:19
Joined
Mar 13, 2010
Messages
162
Hi,

So will I need to get the web host to change the HTML to get this working as you suggested?

Thank you for the help again!

Phil.
 

pr2-eugin

Super Moderator
Local time
Today, 10:19
Joined
Nov 30, 2011
Messages
8,494
I would say so.. As mentioned, without having a Unique ID you will not be able to refer to the Control, as there is ambiguity.. If you use the Name, both Yes and No options share a common name.. Hope that makes sense..
 

abbaddon223

Registered User.
Local time
Today, 02:19
Joined
Mar 13, 2010
Messages
162
Hi, yes it makes total sense and thank you for the advice! Off to speak to the web developer now!!

Chers,

Phil.
 

Users who are viewing this thread

Top Bottom