-1

i have a textarea text "ez.aaaa.value" i want to typing a text and when i select option , redirect automatically to google.com/search?tbm=isch&q= + ((value textarea))

image

Example :

........
<option value="href='http://www.google.com/search?tbm=isch&q=' + ez.aaaa.value">google search</option>
........
moon90
  • 53
  • 1
  • 3
  • 10
  • What is this select for?? – Eugine Joseph Feb 12 '17 at 08:07
  • Explain your question – Moxet Khan Feb 12 '17 at 08:08
  • Have you tried `$( "#myselect option:selected" ).text(); (or val())` – Eugine Joseph Feb 12 '17 at 08:10
  • Possible duplicate of [Get selected value in dropdown list using JavaScript?](http://stackoverflow.com/questions/1085801/get-selected-value-in-dropdown-list-using-javascript) – Debug Diva Feb 12 '17 at 08:12
  • Are you looking to get the value of the selected item or are you trying to dynamically set the value inside of a select by selecting the option programmatically? Or are you trying to dynamically add another option to your select? – creativekinetix Feb 12 '17 at 08:14
  • @EugineJoseph .. i have a textarea text "ez.aaaa.value" i want to type a text and when i select option , redirect automatically to http://www.google.com/search?tbm=isch&q= + ((value textarea)) – moon90 Feb 12 '17 at 08:17
  • @MoxetKhan Khan .. i have a textarea text "ez.aaaa.value" i want to type a text and when i select option , redirect automatically to http://www.google.com/search?tbm=isch&q= + ((value textarea)) – moon90 Feb 12 '17 at 08:17
  • @creativekinetix .. i have a textarea text "ez.aaaa.value" i want to type a text and when i select option , redirect automatically to http://www.google.com/search?tbm=isch&q= + ((value textarea)) – moon90 Feb 12 '17 at 08:20
  • Ok. Then the selected one is the correct answer. Plus you need to add the encodeURIComponent to the query.value. so that, the spaces and the other special characters will be removed. – Eugine Joseph Feb 12 '17 at 09:19

2 Answers2

2

This should do it.

the location.href is what you would use to link out.

this refers to the select and selectedIndex returns the number of the selected option.

var sel = document.getElementById('mysel'),
    query = document.getElementById('myquery');

sel.addEventListener('change' , function() {
  console.log(this.options[this.selectedIndex].value + query.value);
  
  // this would be how to link below
  // location.href = this.options[this.selectedIndex].value + query.value;
});
<input type='text' id="myquery">
<select id="mysel">
  <option>SELECT ONE</option>
  <option value="http://google.com?q=">google</option>
  <option value="http://bing.com?q=">bing</option>
</select>
creativekinetix
  • 357
  • 1
  • 7
0

Add select with ID outside of your option and then try this way

JS

var e = document.getElementById("select-menu");
var strUser = e.options[e.selectedIndex].value;
console.log(strUser);

HTML

<select id="select-menu">
<option value="href='http://www.google.com/search?tbm=isch&q=' + ez.aaaa.value">google search 1</option>
<option value="href='http://www.google.com/search?tbm=isch&q=' + ez.aaaa.value" selected="selected">google search 2</option>
</select>
A l w a y s S u n n y
  • 36,497
  • 8
  • 60
  • 103