开发者

Working with dropdownlistbox in html

I am using dr开发者_开发知识库opdownlist 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 .


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>


    <select id='derp' onchange="changeVal(this,'changeme');">  <!-- declare select, set onchange to point to changeVal JS -->
        <option value='test'>test</option>
    </select>
    <input id='changeme' />
    <script type='text/javascript'>

        function changeVal(el,changeElID){

            var changeEl = document.getElementById(changeElID); // Get input to change
            changeEl.value = el.options[el.selectedIndex].value; // Change input value to value of selected index

        }
    </script>

[EDIT] re-reading the question it sounds like you are trying to change the name of the input box...if that is the case, change changeEl.value to changeEl.name


HTML:

<table cellspacing="0" cellpadding="1" rules="all" border="0" id="gvLanguage">
    <tr>
        <td align="left">
            <select id="ddlLanguage" style="width: 230px;">
                <option value="0">[Select]</option>
                <option value="1">Afrikaans</option>
                <option value="2">Akan</option>
                <option value="3">Albanian</option>
                <option value="4">American</option>
            </select>
        </td>
    </tr>
    <tr>
        <td>
            Selected Value: <label id="lblChange" ></label>
        </td>
    </tr>
</table>

JQUERY:

$(document).ready(function(){
    $("#ddlLanguage").change(function(){
        var vSelectedValue  = $("option:selected",$(this)).text();
       $("#lblChange").text(vSelectedValue);
    });
});

CLICK HERE TO SEE THE DEMO

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜