在html中使用dropdownlistbox

San*_*eep 5 html javascript

我在我的html页面中使用dropdownlist和一个标签.我想在选择我的下拉列表框时更改标签名称.这怎么可能?

请给我任何帮助.

Jos*_*eti 1

检查这个例子

它将更改标签的属性“名称”及其文本内容(读取其新的名称属性值)以查看更改的效果。

<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>
Run Code Online (Sandbox Code Playgroud)