Jump to content



Photo

Select Multiple Dropdown Items

dropdown listbox javascript

  • Please log in to reply
2 replies to this topic

#1 ☠ℬαłłℓℯωℯ♭☠

☠ℬαłłℓℯωℯ♭☠

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 39 posts
  • OS:Windows 8
  • Total Memory:More Than 9Gb
  • Framework:v3.5 & v4.0
  • License:Developer Edition

Posted 16 April 2015 - 07:03 PM

I'm stuck, I need to select 2 items on a dropdown menu (listbox) but cannot find native ability to do it within ubot. I'd imagine that I will need to accomplish this using Javascript. Does anyone have experience with this? I have pasted the code for the listbox/dropdown menu below:

<table cellspacing='0' cellpadding='3' border='0'>      <tr><td valign='top'><b>Items</b>&nbsp;</td><td  class="internalColumn"><label for='ITEMS'><select style=' width: 100%;' title="Select ITEMS to search.  Hold down CTRL to select multiple counties." id='ITEMS' name='ITEMS' size='7' multiple='multiple'><option title="All Counties.  Use the CTRL key to select multiple individual counties." value='' selected='selected' >-- ALL --</option><option  value="58" title="Red">Red</option><option  value="59" title="White">White</option><option  value="60" title="Blue, WA">Blue</option><option  value="61" title="Yellow">Yellow</option><option  value="51" title="Green">Green</option></select></label></td></tr> <tr><td colspan='2'><i>Hold down CTRL to select multiple items</i></td></tr>

☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢

 


#2 LoWrIdErTJ - BotGuru

LoWrIdErTJ - BotGuru

    Botguru.net

  • Moderators
  • 4850 posts
  • LocationMichigan
  • OS:Windows 10
  • Total Memory:8Gb
  • Framework:v4.5+, unsure
  • License:Developer Edition

Posted 16 April 2015 - 11:01 PM

load html("<table cellspacing=\'0\' cellpadding=\'3\' border=\'0\'>      <tr><td valign=\'top\'><b>Items</b>&nbsp;</td><td  class=\"internalColumn\"><label for=\'ITEMS\'><select style=\' width: 100%;\' title=\"Select ITEMS to search.  Hold down CTRL to select multiple counties.\" id=\'ITEMS\' name=\'ITEMS\' size=\'7\' multiple=\'multiple\'><option title=\"All Counties.  Use the CTRL key to select multiple individual counties.\" value=\'\' selected=\'selected\' >-- ALL --</option><option  value=\"58\" title=\"Red\">Red</option><option  value=\"59\" title=\"White\">White</option><option  value=\"60\" title=\"Blue, WA\">Blue</option><option  value=\"61\" title=\"Yellow\">Yellow</option><option  value=\"51\" title=\"Green\">Green</option></select></label></td></tr> <tr><td colspan=\'2\'><i>Hold down CTRL to select multiple items</i></td></tr>")
comment("Deselects all")
run javascript("select.selectedIndex = -1;")
comment("Will select more than 1")
run javascript("var optionsToSelect = [\'White\', \'Green\'];
var select = document.getElementById( \'ITEMS\' );

for ( var i = 0, l = select.options.length, o; i < l; i++ )
\{
  o = select.options[i];
  if ( optionsToSelect.indexOf( o.text ) != -1 )
  \{
    o.selected = true;
  \}
\}")



#3 ☠ℬαłłℓℯωℯ♭☠

☠ℬαłłℓℯωℯ♭☠

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 39 posts
  • OS:Windows 8
  • Total Memory:More Than 9Gb
  • Framework:v3.5 & v4.0
  • License:Developer Edition

Posted 16 April 2015 - 11:49 PM

 

 

Thanks LoWrIdErTJ, I added the code to a run javascript node and ran the node, but no joy (I probably missed something). I made some revisions to the code you gave which worked. I have posted the code below for future reference for those that might need it:

 

var optionsToSelect = ['White', 'Green'];
var select = document.getElementById( 'ITEMS' );


for ( var i = 0, l = select.options.length, o; i < l; i++ )
{
  o = select.options[i];
  if ( optionsToSelect.indexOf( o.text ) != -1 )
  {
    o.selected = true;
  }
}

☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢☢

 






Also tagged with one or more of these keywords: dropdown, listbox, javascript

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users