WebBrowserEx: Setting value of form dropdown/option boxes?

richt

Member
Licensed User
Hi guys,

Guess this one is aimed at Cableguy mainly but one of you may be able to help.

I'm using the WebBrowserEx library to fill out a web form and although I can easily select and fill text fields I can't find a way to select an option from a dropdown field.

Unfortunately I don't have control over the web form so I can't just recode the HTML.

Thanks in advance,

Rich
 

warwound

Expert
Licensed User
Longtime User
Take a look at this javascript function:

B4X:
function setOption($select, $value){
   //   this function accepts 2 parameters
   //   $select is a HTML select element
   //   $value is an option value (string) within the select element to find and select if it exists otherwise no change is made to the select element's options
   //    the function will return true if $value is found in $select and selected otherwise it'll return false
   var $options=$select.options, $i=$options.length;
   while($i--){
      if($options[$i].value===$value){
         $options[$i].selected=true;
         return true;
      }
   }
   return false;
}

You'll need to execute some javascript to get the select element and then call this function to set the desired value.

You can get all select elements with this javascript:

B4X:
var selects=document.getElementsByTagName('select');

selects is an object that can be treated as an array.

A lot depends on how you can get the desired select element from the web page - can you post the form's HTML?

Martin.
 

richt

Member
Licensed User
Hi Warwound,

Thanks for posting. I think you're answer is aimed at the Android platform though, I'm coding in B4PPC on the windows desktop.

I've done some more digging and I think setting form select options via Cableguy's library is beyond the scope of it's current code. I might have to break out the ole' SharpDevelop.

Cheers,
Rich
 

warwound

Expert
Licensed User
Longtime User
LOL that's why i didn't recognise the reference to WebBrowserEx library!!

Martin.
 

Cableguy

Expert
Licensed User
Longtime User
Sorry for the late reply...

I intended to add some more features to the DLL, but I had some stuff happening in my life that strayed me away from the Forum, and computers overall...
Still, if you have the name of the dropdown element/control, you can use the getdocument method, fetch the element, add the necessary html code and re-feed it to the WebBrowserEx.

I konw this is possible because I managed to auto-Post a form by adding html to the original page, so any other html elemente can be managed/changed if you know html.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…