locked
Invoking script to select option in HTML drop down menu

    Question

  • HelloI have posted this under JavaScript even though I am writhing the app in C# because it is about JavaScript.

    I'm trying to use

    WebView.InvokeScript

    to make my windows 8 app select an item from a drop down menu on a home page..


    The code for the page looks like this:

    <span class="select"><select id="edit-language" class="form-select" name="language">
    <option selected="selected" value="da-DK"> Danish, Denmark (Dansk, Danmark)</option>
    <option value="nl-BE"> Dutch, Belgium</option>
    <option value="nl-NL"> Dutch, The Netherlands</option>
    <option value="fi-FI"> Finnish, Finland (Suomi, Suomi) </option>
    <option value="nb-NO"> Norwegian (Bokmål), Norway (Norsk (Bokmål), Norge)</option>
    <option value="sv-SE"> Swedish, Sweden (Svenska, Sverige)</option>
    </select>
    <span class="select-btn"></span>

    I've tried selecting it using something like this but it doesn't work

    if (land == "1")
    {
       try
       {
           signupWebView.InvokeScript("eval", new string[] { string.Format("document.getElementsByName('language')[0].selectOption(1);document.getElementsByName('language')[0].value(nl-BE);") });
       }
       catch (Exception ex)
       {
       }
    }

    I have also tried

    document.getElementsByName("language")[0].selectedIndex=1

    and

    signupWebView.InvokeScript("eval", new string[] { string.Format("Document.GetElementById('edit-language').Document.GetElementsByTa‌​gName('option')[2].SetAttribute('selected', 'selected');") });

    but still no result.. Any help would be much appriciated.






    Thursday, August 15, 2013 10:08 AM

Answers

  • Thanks I had already looked at that page it shows to use the

    .checked

    method that I had already tried but unfortunately that didn't work for my page...

    In the end I have made a completely different solution...

    Friday, August 16, 2013 3:23 PM

All replies