0

suppose i have value 'v' in some variable say 'var', now i want to display Valvo(text respect to value v). any suggestion??

2 Answers2

0

HTML

<select id="sel">
  <option value="Volvo">Volvo</option>
  <option value="BMW">BMW</option>
</select>

JS

var myvar = 'b';

var elem = document.querySelector('#sel option[value^='+myvar.toUpperCase()+']');
if (typeof elem != 'undefined') {
  elem.selected = true;
}

Here you can test -> http://jsbin.com/ehayav/1

mz

mariozski
  • 1,134
  • 1
  • 7
  • 20
0

May be this will help you :

//array of varables
var names = ['apple','banana','valvo','blahblahblah']
//this is your variable
var variable = 'v'
//code to display names starting with the character in your variable
for(i=0;i<names.length;i++)
    if(names[i][0] == variable)
        alert(names[i])

This answer is for my interpretation of your question. EnjoY!

codeVerine
  • 742
  • 3
  • 14
  • Please make your question more clear. What you want to exactly do ? Do you want to dynamically create a select box like this : '' – codeVerine Mar 13 '13 at 10:20