HTML onchange (this.value)

e.klara.k picture e.klara.k · Sep 9, 2015 · Viewed 69.7k times · Source

We found this in our code (we haven't written it by our selfs, and we are new to programmng), can anyone explain what this.value means and how you change it?

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

Thank you!

Answer

SVK picture SVK · Sep 9, 2015

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>

The above example gets you the selected value OnChange event.