admin管理员组文章数量:1187854
I used this above html code for my project..but i don't know how to get value of above input using javascript
<form>
<input type="color" id="favcolor">
</form>
can someone help me ?
Thanks
I used this above html code for my project..but i don't know how to get value of above input using javascript
<form>
<input type="color" id="favcolor">
</form>
can someone help me ?
Thanks
Share Improve this question asked May 15, 2014 at 18:38 user3624843user3624843 1751 gold badge1 silver badge8 bronze badges 7 | Show 2 more comments2 Answers
Reset to default 25To simply get the value
document.getElementById("favcolor").value;
You can add an event listener if you want to get the color when the selection changes. You’d do something like this:
var theInput = document.getElementById("favcolor");
theInput.addEventListener("input", function(){
var theColor = theInput.value;
// Do something with `theColor` here.
}, false);
<input id="favcolor" type="color"/>
Here’s a working JSFiddle.
We can simply assign the color value to the label.
Sample code is here
<label id ="colorVal">Select color</label>
<input type="color" id ='color'>Value</input>
JS Code
let colorInput = document.getElementById('color');
colorInput.addEventListener('input', () =>{
document.getElementById('colorVal').innerHTML = colorInput.value;
});
Sample codepen link
https://codepen.io/ragi_jay/pen/poRMwMX
本文标签: htmlhow to get value of typequotcolorquot input using javascriptStack Overflow
版权声明:本文标题:html - how to get value of type="color" input using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738355200a2079705.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
value
attribute? – ComFreek Commented May 15, 2014 at 18:39value
attribute (of the DOM object). It works. – ComFreek Commented May 15, 2014 at 18:42