HTML onchange (this.value)

We found this in our code (we did not write it ourselves, and we are new to programming), can anyone explain what this means? and how do you change it?

<select id="sel_target" onchange="paint(this.value);sendid(value); highlight(value);move_to(value)">

Thanks!

+6
source share
2 answers

this.value represents the selected value.

Example:

function getComboA(sel) {
    var value = sel.value;  
}

<select id="comboA" onchange="getComboA(this)">
<option value="">Select combo</option>
<option value="Value1">Text1</option>
<option value="Value2">Text2</option>
<option value="Value3">Text3</option>
</select>

In the above example, you will get the selected value of the OnChange event.

+13
source

For a numeric type, a text field

Add .00 if available

<input type="number" step=".01" onchange="addZeroes(this)" />

function addZeroes(ev) {
    debugger;
    // Convert input string to a number and store as a variable.
    var value = Number(ev.value);
    // Split the input string into two arrays containing integers/decimals
    var res = ev.value.split(".");
    // If there is no decimal point or only one decimal place found.
    if (res.length == 1 || res[1].length < 3) {
        // Set the number to two decimal places
        value = value.toFixed(2);
    }
    // Return updated or original number.
    if (ev.value != "") {
        ev.value = String(value);
    }
}
0
source

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


All Articles