Harriz
Harriz

Reputation: 77

Set value to other input field

Here an html code

<select id="product">
  <option value="laptop">Laptop</option>
  <option value="candy">Candy</option>
  <option value="ebook" selected="selected">Ebook</option>
</select>
<input type="text" id="priceProduct">

and this is a javascript code

var e = document.getElementById("product");
var strUser = console.log(e.options[e.selectedIndex].value);
if(strUser == "ebook"){
    console.log('This is ebook');
}

So, i just want to give some value like $ 5.00 to input id priceProduct (I cant even give output to console) from select element. I'm totally lost. I appreciate your answer.

jsfiddle link

Upvotes: 0

Views: 54

Answers (1)

Halcyon
Halcyon

Reputation: 57709

Change your code to:

var e = document.getElementById("product");
var strUser = e.options[e.selectedIndex].value;
console.log(strUser);
if(strUser == "ebook"){
    console.log('This is ebook');
    document.getElementById("priceProduct").value = "$5.00";
}
// -- prints:
// ebook
// This is ebook

console.log doesn't have a return value.

Upvotes: 1

Related Questions