VBA executing javascript, multiple radio buttons with same ID

  • By using an embedded webbrowser, I have managed to navigate to a site, interact with welcoming pop-ups, login with username and password, search for records in a database, access the records, and populate the data on the record for submission. Well, almost. On the final page, there are multiple sections with radio buttons to select, 1 for each category. The problem is, they have the same name. For example (much more simple than the actual source):


    Record to Update...


    1. Choose a day of the week:
    monday, tuesday, wednesday


    2. Choose a time of the day:
    morning, afternoon, evening


    I can automate the choosing based on values in my worksheets, but the problem is that (in this example) the ID for .checked is the same:


    Monday = "A"
    Tuesday = "B"
    Wednesday = "C"


    Morning = "A"
    Afternoon = "B"
    Evening = "C"


    So if I want to pick Monday and Afternoon, it ends up just stopping at choosing tuesday, since it doesn't know that I want the "B" from the next set. Each section to choose has different names (ie, choose_day and choose_time).


    How do I tell the browser which section I want to update, and then move on? I've come to far to be stuck at the very end...


    Thanks!

  • Re: VBA executing javascript, multiple radio buttons with same ID


    Quote from upplink32;639283

    Each section to choose has different names (ie, choose_day and choose_time)

    It's a bit difficult to help with just describing the page; we really need to see the HTML source or the URL, but try something like:

    Code
    WebBrowser1.document.forms(0).elements("choose_day")(0).Checked = True   'Monday
    WebBrowser1.document.forms(0).elements("choose_time")(1).Checked = True   'Afternoon

    assuming those elements belong to the first form [forms(0)].

  • Re: VBA executing javascript, multiple radio buttons with same ID


    Quote from John_w;639318

    It's a bit difficult to help with just describing the page; we really need to see the HTML source or the URL, but try something like:

    Code
    WebBrowser1.document.forms(0).elements("choose_day")(0).Checked = True   'Monday
    WebBrowser1.document.forms(0).elements("choose_time")(1).Checked = True   'Afternoon

    assuming those elements belong to the first form [forms(0)].



    Yes, all the elements belong to the same form. Here is the source (the parts in question), and likely more in here than you need:



    Code
    <font class="LabelFONT">Incident Outcome</font></td><tr><td><label for="incidentOutcome_1_none">
    
    
    <input type="radio" name="incidentOutcome_1_none" id="id_D" value="D" alt="Distress" /><font class="smallFONT">Distress</font></td><td><label for="incidentOutcome_1_none">
    
    
    <input type="radio" name="incidentOutcome_1_none" id="id_N" value="N" alt="Non-Distress"  CHECKED /><font class="smallFONT">Non-Distress</font></td><td><label for="incidentOutcome_1_none">


    So on that section if I wanted to select "non-distress", I'd use:
    browser.Document.getelementbyid("id_N").Checked = True


    Code
    <font class="LabelFONT">     Owner Information</font></td><tr><td><label for="regAccuracyOwner_1_none">
    
    
    <input type="radio" name="regAccuracyOwner_1_none" id="id_A" value="A" alt="Accurate"  CHECKED /><font class="smallFONT">Accurate                        </font></td><td><label for="regAccuracyOwner_1_none">
    
    
    <input type="radio" name="regAccuracyOwner_1_none" id="id_N" value="N" alt="Not Accurate                    " /><font class="smallFONT">Not Accurate                    </font></td><td><label for="regAccuracyOwner_1_none">


    And on this section if I wanted to select "not accurate", I'd use:
    browser.Document.getelementbyid("id_N").Checked = True



    Since both radios that I want to check are id_N - only the first one gets checked and the second stays blank.



    Thoughts? I'm not sure if it's possible to cycle through them, or if there is a way to define each as a static id each time..?

  • Re: VBA executing javascript, multiple radio buttons with same ID


    Try using the name for each

    Code
    browser.Document.all("incidentOutcome_1_none").Checked = True
     browser.Document.all("regAccuracyOwner_1_none").Checked = True
  • Re: VBA executing javascript, multiple radio buttons with same ID


    Quote from Eggcel;639440

    Try using the name for each

    Code
    browser.Document.all("incidentOutcome_1_none").Checked = True
     browser.Document.all("regAccuracyOwner_1_none").Checked = True



    That won't do anything, as there is no radio input by those names to check. There are radio options for each of those sections.

  • Re: VBA executing javascript, multiple radio buttons with same ID


    I don't know why you've posted the above HTML when you said the names of the radio buttons in question are choose_day and choose_time. Post the HTML relevant to the radio buttons you want to 'push'.


    For the 2nd HTML above the following should set the 'Accurate' and 'Not Accurate' options in turn (similar to my previous code):

    Code
    WebBrowser.Document.all("regAccuracyOwner_1_none")(0).Checked = True 
    WebBrowser.Document.all("regAccuracyOwner_1_none")(1).Checked = True

    See if you can apply the same technique to the radio button you said was named 'choose_day'.

  • Re: VBA executing javascript, multiple radio buttons with same ID


    Quote from John_w;639498

    I don't know why you've posted the above HTML when you said the names of the radio buttons in question are choose_day and choose_time. Post the HTML relevant to the radio buttons you want to 'push'.


    The choose_day / time was just an example, as I didn't have access to the source code for the post at the time. Someone asked me for the actual source code, so I posted it when I could.




    Quote from John_w;639498

    See if you can apply the same technique to the radio button you said was named 'choose_day'.


    This worked perfectly, as I can now adjust the () value for the radio for each.



    Thanks a million!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!