Thursday, June 12, 2014

Javascript Multiple Selection

<!DOCTYPE html>
<html>
<script>
function change_value(){
alert("checking point");
if (document.getElementById('11307').value != null) {
  var eMulti = document.getElementById("11307");
  for (var i=0; i< eMulti.options.length; i++) {
    if (eMulti.options[i].selected ==true) {
      document.getElementById('def').value = eMulti.options[i].value +'@@' ;
    }}
} else {
  document.getElementById('def').value = "abc is blank." ;
}

}
</script>
<body>

<input id="def" type='text' value="Intiated!" />


<select id="11307" name="cars" multiple>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>

<button onclick="change_value()">Try it</button>




<p>Hold down the Ctrl (windows) / Command (Mac) button to select multiple options.</p>

</body>
</html>

No comments:

Post a Comment