calling javascript function from <select> onchange

后端 未结 3 1471
青春惊慌失措
青春惊慌失措 2020-12-21 19:15

I am trying to call a javascript function from the onchange attribute of the select tag ! My issue is that I am passing the name attribute of the select to the

相关标签:
3条回答
  • 2020-12-21 19:34

    PHP is run on the server before JavaScript is ever run in the browser. It doesn't get re-evaluated when the user changes the selected item.

    0 讨论(0)
  • 2020-12-21 19:46

    HTML:

    <body>
        <form action="" method="post">
            <select name="slct" id="name" onchange="rohan(this.value)">
                <option>Select</option>
                <option value="yes" selected="selected"> yes </option>
                <option value="nopes"> nopes </option>
                <option value="may be"> May be </option>
                <option value="dont know"> dont know </option>
            </select>
        </form>
    </body>
    

    JS:

    <script>
        function rohan(value)
        {
            //you can get the value from arguments itself
            alert(value);
        }
    </script>
    
    0 讨论(0)
  • 2020-12-21 19:48

    No put in tag HTML attribute javascript, onchange is better in the script:

    <script>
        var b=document.getElementById('name');
            b.onchange=function (){
            var a=document.getElementById('name').value;
            console.log(a);
        }
    </script>
    
    0 讨论(0)
提交回复
热议问题