Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with dropdownlistbox in html

I am using dropdownlist and one label in my html page. I want to change name of label on selection of my dropdownlist box. How is it possible?

pls povide any help for me .

like image 574
Sandeep Avatar asked Nov 04 '22 14:11

Sandeep


1 Answers

Check this example.

It will change the attribute 'name' of your label, and its text content (reading its new name attribute value) to see the change in effect.

<script type="text/javascript">
function changeValue(select) {

  var value =  select.options[select.selectedIndex].value;
  var label =  document.getElementById('mylabel');

  label.setAttribute('name', value);
  label.innerHTML = label.getAttribute('name');

} 
</script>

<select name="selectcity" onchange="changeValue(this);" >
    <option>Mumbai</option>
    <option>Delhi</option>
</select>
You selected: <label id="mylabel" name="citylabel"></label>
like image 184
Jose Faeti Avatar answered Nov 14 '22 23:11

Jose Faeti