I have a dropdownlist and I want that when my document is loaded the value currently selected in the dropdown be in the label.

I have a script as

    var x  = document.getElementById('vatRate'); 

    document.getElementById('pricingConsumerVat').textContent = x; 

I get the value in the variable x, however I am not able to display the same in my label.

Why so ?

My label is as

<label id="pricingConsumerVat"></label>

Any jQuery solutions is most welcomed too.

有帮助吗?

解决方案

Try this..

document.getElementById('pricingConsumerVat').textContent = x.value;

or

document.getElementById('pricingConsumerVat').innerHTML = x.value;

其他提示

var x  = document.getElementById('vatRate'); 

document.getElementById('pricingConsumerVat').innerHTML = x.value; 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top