0

I want to enter the text selection for the following select field:

<select name="Payerid" id="Payerid" class="text" name="Payerid">
    <option value="383">Aetna Healthcare</option>
    ...

Using VBA, I know I can use: (If you give me the syntax in another language, I'll convert)

  IE.getElementById("Payerid").Value = "383"

but there about 100 options so I don't want to keep track of the values (which are meaningless to me) or changes the website developers make.

So is there a way to enter the text into the select field? I tried:

 IE.getElementById("Payerid").Text = "Aetna Healthcare"

but that didn't work.

Thanks

Nelson
  • 11
  • 2
  • Loop over the options within the select, and set the value when you hit the one with the desired text. You can wrap that up in a reusable function. See Lansman's answer here: http://stackoverflow.com/questions/15003015/using-excel-vba-to-change-the-value-of-a-dropdown-menu-on-a-website – Tim Williams Feb 04 '15 at 17:33

1 Answers1

0

You mean you want to change the value? That's just $('select').val('value you want');, using Jquery.

If you're wanting to obtain the value based on what is in the text field, that is as below, derived in part from this post.

var pick = "hey";

var value_pick = $('option').filter(function () { return $(this).html() == pick; }).val();
console.log(value_pick);

$("select").val(value_pick);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<select>
  <option value="1" >hey</option>
  <option value="1" >baha</option>
  <option value="1" >yo</option>
</select>
Community
  • 1
  • 1
PeterM
  • 439
  • 2
  • 9
  • "You mean you want to change the value? That's just $('select').val('value you want');, using Jquery." – Nelson Feb 05 '15 at 15:25
  • "You mean you want to change the value? That's just $('select').val('value you want');, using Jquery." No, that will input the value for the option. I want to input what the user would input, not the value. In the case of the example I provided, I want to programmatically input "Aetna Healthcare" into the select field not "383" which is the value. – Nelson Feb 05 '15 at 15:30
  • Nelson, but when you change the value, it changes the corresponding text automatically. So, if you use the .val('383'), the field will say 'Aetna Healthcare'. That's what you want, unless I'm mistaken. Now, if you want to programmatically update it with input being text (ie., you want to be able to program .val('Aetna Healthcare'), then you can use the function above to obtain the corresponding value to set. Here's a fiddle: http://jsfiddle.net/Lcf2so9f/ – PeterM Feb 09 '15 at 18:56
  • I do not want to enter the VALUE. I do not want to enter "383" in this example. I want to enter the text into the select field programmatically as if I was typing it in the box. For example, if I was typing in the box, I would type: "Aetna Healthcare" not "383". In fact when I started to type "aet", Aetna Healthcare would show up and I would select that. So I want to programmably enter "Aetna Healthcare" and get the correct selection. Pretend we don't know that value of "Aetna Healthcare".is "383". Let's pretend we don't know the value of any of the options. – Nelson Feb 10 '15 at 20:09
  • Nelson, the Fiddle I posted does that. It lets you programmatically enter your text (eg., "volvo") and that option is automatically selected without needing to know the value. – PeterM Feb 11 '15 at 09:28