html5 - Javascript: how to get seleted option value that is in the datalist with inside select -


on below code, trying value of selected 'option' 'select' element in 'datalist' element. have tried something, but, couldn't. expecting solution in javascript. of now, alerts first option value change option value. should alert actual option value when change option value on input box. example if select 'blueberry' should omit 'bluberry'.

<html>     <head>         <title>html 5 test elements</title>     </head>     <body>         <div>             <label>your favorite fruit:                 <datalist id="fruit">                     <select name="fruits">                         <option value="blackberry">blacskberry</option>                         <option value="blackcurrant">blackcurrant</option>                         <option value="blueberry">blueberry</option>                     </select>                     if other, please specify:                 </datalist>                 <input type="text" name="fruit" list="fruit"/>             </label>              <script type="text/javascript">                 document.getelementsbyname("fruit")[0].onchange = function (event) {                     var evt = event || window.event;                     var parelem = evt.srcelement || evt.target;                     alert(document.getelementsbyname("fruits")[0].options[document.getelementsbyname("fruits")[0].selectedindex].value);                 }             </script>         </div>     </body> </html> 

any idea? please.

first of all, can remove <select> element , keep <datalist> , nested <options>. use datalist. can use input event check change on <input> connected datalist

here working fiddle: http://jsfiddle.net/bkab62rq/


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -