最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Trying to set selected value of DropDown in Javascript with encoded value - Stack Overflow

programmeradmin4浏览0评论

I have a dropdown which lists heights, like this:

5' 9"
5' 10"
5' 11"
6' 0"

Etc.

When I view source, it looks like this:

<option value="5' 9&quot;">5' 9&quot;</option>
<option value="5' 10&quot;">5' 10&quot;</option>
<option value="5' 11&quot;">5' 11&quot;</option>
<option value="6' 0&quot;">6' 0&quot;</option>

How can I set the selected value of my dropdown box via Javascript when those characters are in there?

I tried:

document.GetElementById("myDDL").value = '5\' 11\"';

However that is not working and I'm just taking stabs in the dark.

Thank you!

I have a dropdown which lists heights, like this:

5' 9"
5' 10"
5' 11"
6' 0"

Etc.

When I view source, it looks like this:

<option value="5' 9&quot;">5' 9&quot;</option>
<option value="5' 10&quot;">5' 10&quot;</option>
<option value="5' 11&quot;">5' 11&quot;</option>
<option value="6' 0&quot;">6' 0&quot;</option>

How can I set the selected value of my dropdown box via Javascript when those characters are in there?

I tried:

document.GetElementById("myDDL").value = '5\' 11\"';

However that is not working and I'm just taking stabs in the dark.

Thank you!

Share Improve this question asked Feb 11, 2010 at 9:11 user53885user53885 3,82912 gold badges36 silver badges45 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

Works fine for me on Safari 4, MobileSafari 3.1, Firefox 3.5 and Opera 10.10

Did you try

document.getElementById("myDDL").value = '5\' 11"';

with a small g?

If you know in advance which option you want to select, you could do

document.getElementById("myDDL").selectedIndex = 2; // 5' 11"
$("#single_example").val(2).trigger("change");
发布评论

评论列表(0)

  1. 暂无评论