Creating selection result in popup in javascript

So this uses javascriptand HTML.

For instance:

<select name='test' >
    <option value='1'>
    <option value='2'>
    <option value='3'>
</select>

If someone selects the value of parameter 2 (from the drop-down list), I want a popup to appear. However, if they choose the value of parameter 1 or the value of parameter 3 (from the drop-down list), I do not want anything.

How can i do this?

thank

+3
source share
3 answers

Add the id to select ( <select name='test' id='test'>). Then add (after <select>):

<script>
document.getElementById("test").onchange = function(){
    if (this.options[this.selectedIndex].value == '2') {
        alert('hello world!');
    }
}
</script>
+3
source

You can make an event handler as follows:

<script type="text/javascript">
function pop(a) {
    if (a.value==2) alert('two');
}

</script>

and for html:

<select id="sel" onchange="pop(this)">
<option value="1">one</option>
<option value="2">two</option>

0
source

- :

<select name='test' onchange='if(this.value==2) alert("TEST")'>
    <option value='1'>
    <option value='2'>
    <option value='3'>
</select>
0

Source: https://habr.com/ru/post/1748056/


All Articles