display selected item from dropdown onchange function into html label through javascript , please help how to it

后端 未结 2 336
轻奢々
轻奢々 2021-01-03 07:49
提交评论

  • 2021-01-03 08:24

    Try putting the onChange attribute in the select tag.

    Example: http://jsfiddle.net/r6Fus/

    HTML:

    <div id="label"></div>
    <select id="mySelect" onchange="copy();">
        <option value="">Select a person:</option>
        <option value="tcs" >tcs</option>
        <option value="wipro" >wipro</option>
        <option value="Hcl" >Hcl</option>
        <option value="krystal kones" >krystal kones</option>
    </select>
    

    Javascript:

    function copy() {
        document.getElementById("label").innerHTML = document.getElementById("mySelect").value
    }
    

    Otherwise you could use jQuery.

    0 讨论(0)
  • 提交回复
    热议问题