0

I want to create a command from the option and go to javascript then display it in the input box.

<select id="change"> <option>Cat</option> <option>Dog</option> <option>Fish</option> </select> <script type="text/javascript"> show('Cat'); </script> <input/> 

when I choose one of the options, then the contents automatically in the javascript changed. and the reload function runs then displays the result in the input box.

0

3 Answers 3

2

You can try adjusting to your best needs from this snippet

<select id="change"> <option>Cat</option> <option>Dog</option> <option>Fish</option> </select> <script type="text/javascript"> document.getElementById('change').addEventListener('change', function(e) { document.getElementsByTagName('input')[0].value = e.target.value; }); </script> <input/> 

If you want to call show with selected value you can have

document.getElementById('change').addEventListener('change', function(e) { var selected = e.target.value; show(selected); }); 
Sign up to request clarification or add additional context in comments.

3 Comments

I mean, how to change the contents of javascript via the options command. so when I choose one of the options, the automatic value in javascript is changed in the show('xxValueFromOptionxx'); code
you can replace document.getElementsByTagName('input')[0].value = e.target.value; with show(e.target.value);
problem solved. thanks
1

Try this.

function a(select) { var input = document.getElementById("input"); if (select.value !== "Select option") { input.value = select.value; } else { input.value="" } }
<select id="change" onchange="a(this)"> <option>Select option</option> <option>Cat</option> <option>Dog</option> <option>Fish</option> </select> <input id="input" />

Comments

1

Hm not sure what your are trying to achieve but this works if your use a normal browser:

//Targets select = document.getElementById("change"); print = document.getElementById("value"); //Function print option printOption = function(loc, option) {	loc.innerHTML = option; } //Function force value optionPicker = function(option) {	select.value = option; printOption(print, option); }; //Change Listener document.addEventListener("change", function(e){	if(e.target.id === "change")	printOption(print, e.target.value); }, false); //Commands optionPicker("Dog");
<select id="change"> <option>Cat</option> <option>Dog</option> <option>Fish</option> </select> <div id="value"></div>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.