Edin Puzic
Edin Puzic

Reputation: 1048

Display value from select list using javascript

how can I display option value from the select list in my consol.log without selecting it twice. Now it works but I need to click twice to diplay it.

JS

function formatClick() {
    screenName = document.getElementById("linkscreen").value;
    console.log(screenName);
}

JSFIDDLE

Upvotes: 0

Views: 34

Answers (1)

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67217

At this context, click event seems inappropriate. Use change event instead.

  .. .. onchange="formatClick()">

DEMO

And additionally, I would advise you to not to use an inline event handler. Use a dedicated event handler like below,

document.getElementById("linkscreen").addEventListener("change", formatClick, false);

DEMO

Upvotes: 2

Related Questions