Input Text value Property - work together with dropdown list - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

Input Text value Property - work together with dropdown list

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form>
Select numbers:<br>
<select id="no">
    <option>0</option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
</select>//  w  w  w  .  ja  va2  s .  co  m
<input type="button" onclick="myFunction()" value="-->">
<input type="text" id="result" size="20">
</form>

<script>
function myFunction() {
    var no = document.getElementById("no");
    var option = no.options[no.selectedIndex].text;
    var txt = document.getElementById("result").value;
    txt = txt + option;
    document.getElementById("result").value = txt;
}
</script>

</body>
</html>

Related Tutorials