How to set value in a hidden field and hide a div using Javascript? [closed]
i am newbie to javascript and i want to know how to set value in a hidden field using java script and how to hide a div using java script ?
how to set value in a hidden field using java script
Set the value for hidden field:
var el = document.getElementById('hidden field id');
el.value = 'some value';
and how to hide a div using java script
Hide a div:
var el2 = document.getElementById('div id');
el2.style.display = 'none';
You might want to peform either of those actions if some element gets clicked, you could do:
var btn = document.getElementById('button id');
btn.onclick = function(){
var el = document.getElementById('hidden field id');
el.value = 'some value';
}
where id can be set for an element like this:
<div id="myid">
Have a look at:
- JavaScript Tutorial
精彩评论