Js: Add Comma To A String
I'm trying to add comma to a string and show that into label through following function : HTML :
Solution 1:
Label doesn't use value to assign values. It uses innerHTML. Try the below.
document.getElementById('result').innerHTML = result;
As pointed out in comments, it is better to use textContent or innerText options to set value (only for plain text) as they are safer than innerHTML.You can use it as shown below.
document.getElementById('result').textContent = result;
or
document.getElementById('result').innerText = result;
innerText property is not supported by FireFox and it uses the textContent property. Hence, the below method will work across browsers.
var resultDiv = document.getElementById('result');
if (typeof resultDiv.innerText === 'string') {
resultDiv.innerText = result;
}
else {
resultDiv.textContent = result;
}
Sources:
Solution 2:
Try this
document.getElementById('result').innerHTML = result;
instead of .value, use .innerHTML
Solution 3:
Use innerHTML instead of value:
document.getElementById('result').innerHTML = result;
JSFIDDLEhttp://jsfiddle.net/J4mLD/1/
Also note, to use inline event handlers in JSFIDDLE you must set the second dropdown to one of the nowrap options.
Post a Comment for "Js: Add Comma To A String"