2

hello friends i need a small help regarding separation of options from select

    <html>
<select> 
 <option> mango</option>
 <option> apple</option>
 <option> apple</option>
 <option> grapes</option>
 <option> mango</option>
 <option> grapes</option>
</select>
</html>

i want to seperate all mangoes to one textbox and apples to another and so on... dynamically

please helpme with the code... thank you

1 Answers1

0

I made a fiddle for you. here it is: DEMO

Thanks for SO friends that help me. BTW, for me to achieve what you want, If you notice, I store all values taken from option tag to an array. Then make again a new array to store the filtered duplicate values. And for final step is to append a textbox that has a value of those three. here's some of the codes:

var x = document.getElementById("fruits");
var getfruits = [];
var i;
for (i = 0; i < x.length; i++) {
    x.options[i].text;
    var y = x.options[i].text;
    getfruits.push(y);
}

EDITED:

I add here some of fruits to see more effectiveness. You can also add some as you want. HERE

NOTE: If you want to use value of the option tag instead of its text just replace this

var y = x.options[i].text;

to this

var y = x.options[i].value;

AlexJaa
  • 389
  • 7
  • 20
  • For more additional questions regarding this visit here http://stackoverflow.com/questions/25216885/overwrite-duplicate-value-in-an-array-javascript#25216924. I'd made a question relative to yours. – AlexJaa Aug 09 '14 at 10:09