Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JavaScriptQuestions document.getElementById

Have Programming Question? Ask it here!
 
 
 


Java Coder
document.getElementById
1 Answer(s)      a year and 8 months ago
Posted in : JavaScript Questions


What is the use of document.getElementById method in JavaScript? Please provide a short example of this method in HTML.


Advertisement
View Answers

December 29, 2012 at 1:02 PM


JavaScript Tutorial - document.getElementById

document.getElementById is a method in JavaScript, which is used to accesses the first element with the specified id. Where ID is required. We can take a simple example of displaying date in a WebPage on button Click.

<!DOCTYPE html>
<html>
<head>
<script>
function displayDate()
{
document.getElementById("demo").innerHTML=Date();
}
</script>
</head>
<body>

<h1>Date Example in JavaScript</h1>
<p id="demo">click to Display Date.</p>

<button type="button" onclick="displayDate()">Display Date</button>

</body>
</html>


Related Tutorials/Questions & Answers:
document.getElementById
document.getElementById  What is the use of document.getElementById method in JavaScript? Please provide a short example of this method in HTML
JavaScript removeAttribute method
of an element. Most of the times it is used with the document.getElementById... removeAlignment(){ var read = document.getElementById("txt"... document.getElementById(), thereafter we can apply removeAttribute() method. Here
Advertisements
optimze page load - Java Beginners
(){ if (document.getElementById("page_txf") != null) { document.getElementById("page_txf").value = ; } setDisplayFilter(); //document.getElementById("searchList").focus
Javascript validation - Java Beginners
will be displayed. nameValue=document.getElementById(name).value; var re = /^\d{5}([\-]\d{4})?$/; if(nameValue == '' || nameValue == null ){ document.getElementById(msg).innerHTML='This field is Required'; document.getElementById(name
Javascript Loop Error - WebSevices
= document.getElementById('V_cname').value form.V_cperson.value = document.getElementById('V_cperson').value form.V_desgination.value = document.getElementById('V_desgi').value form.V_address.value = document.getElementById('V_address').value
simple ajax Request and Response code...
==4) { // alert("visible"); document.getElementById("theResults").innerHTML=request.responseText; document.getElementById("theResults... { //alert("hidden"); document.getElementById("theResults").innerHTML
Line From code
Line From code  document.getElementById("demo").innerHTML=Date(); Please explain each and every word in this line
wp-autolinker - Java Beginners
; document.getElementById('wp_autolinker_keyword_'+index).disabled = false; document.getElementById('wp_autolinker_target_url_'+index).disabled = false; document.getElementById('wp_autolinker_link_text_'+index).disabled = false
Javascript background color - Java Beginners
if(document.getElementById('myName').style.backgroundColor=='rgb(254,204,204)') and if(document.getElementById('myName').style.backgroundColor=='rgb(254,204,204)') ...(){ if (document.getElementById('in').value=="amit"){ document.getElementById
How to change focus among multiple select boxes?
= document.getElementById("list1").value; var option2 = document.getElementById("list2").value; var option3 = document.getElementById("list3").value; if(option1 != "") { document.getElementById("list2").selectedIndex = -1
Ajax - Ajax
) { if(document.getElementById("emp_id").value!="-1") { xmlHttp=GetXmlHttpObject() if (xmlHttp==null... Select Employee Id"); } } function stateChanged() { document.getElementById("ename").value =""; document.getElementById("emp_id").value
enabling and disabling a hyperlinks using javascript only
function disableLink() { document.getElementById('listOfOwners').disabled=true; document.getElementById('listOfOwners').removeAttribute('href'); document.getElementById('listOfOwners').style.textDecoration = 'none
Small clarification
Small clarification  This function is used to search and select particular word. In this function document.getElementById('d')); getElementById...(); textRange.findText("glitters"); textRange.select(document.getElementById('d
hide division - JSP-Servlet
showhide() { document.getElementById('div2').style.visibility = 'visible'; document.getElementById('div1').style.visibility = 'hidden'; } Hello World
java script - Java Beginners
hide() { if (document.getElementById) { document.getElementById('cancel
jsp code - Java Server Faces Questions
function inputtype(rad1) { var strValue=document.getElementById(rad1).value...=document.getElementById(rad1).value; alert(strValue); document.getElementById.... ============================================ document.getElementById("mydiv").innerHTML=strValue
Combo box value Error - WebSevices
']); } document.frmProposal.hdVisa.value = document.getElementById('cmbVisa').value; Error... convert() { var val1 = document.getElementById("value1").value; var targetDiv = document.getElementById("target"); targetDiv.value
Javascript Loop Error - WebSevices
locId = document.getElementById('cmbLocationVendor') if(locId != null) { form.V_location.value = document.getElementById('cmbLocationVendor').value...: " + Vendor); alert("Enter Vendor Name"); alert(document.getElementById('V
jsp help - JSP-Servlet
addRow(tableID) { var table = document.getElementById(tableID); var rowCount...); if(document.getElementById("psize").value>1) { document.getElementById("psize").value = document.getElementById("psize").value-1
Urgent query about CreateTextFile using Javascript
("Scripting.FileSystemObject"); var write_id; write_id = document.getElementById('Name').value...(write_id, true,false); s.WriteLine(document.getElementById('Name').value); s.WriteLine(document.getElementById('Department').value); s.WriteLine
Ajax not working in jsp
= document.getElementById("img" + txtField.id.substring(3) + "Error"); var btnSignUp = document.getElementById("btnSignUp"); if (!eval... = document.getElementById("btnSignUp"); var txtUID = document.getElementById("txtUID
Javascript & AJAX query - Ajax
validate() { var len; if(document.getElementById("psize").value...(document.getElementById("psize").value); } for(var i=1; i<=len; i++) { var person = "person" + i; if(document.getElementById(person).value
javascript - Java Beginners
= document.getElementById('mainContainer'); var newDiv = document.createElement...(){ document.getElementById...').style.visibility='hidden'; document.getElementById('pro
ajax code with jsp - Ajax
= document.getElementById("tamt").value; var tenure = document.getElementById("tenure").value; var cal = tamt/tenure; document.getElementById("calid... total_amount = document.getElementById("value1").value; var tennure
JavaScript Checkbox getElementById
. document.getElementById("image").style.visibility = 'visible'- This makes the image visible. document.getElementById("image").style.visibility = 'hidden'- This makes... showImage(){ if(document.getElementById('check').checked==true
Change background color of text box - Java Beginners
check(){ if (document.getElementById('in').value=="amit"){ document.getElementById('in').getAttributeNode('class').value="correct"; }else { document.getElementById('in').getAttributeNode('class').value="incorrect
how to set value of dropdown list
=== " ; } %> function setValue(h, m, a) { document.getElementById("hour").selectedIndex=h; document.getElementById("min").selectedIndex=m; document.getElementById("am").selectedIndex
how to set value of dropdown list
=== " ; } %> function setValue(h, m, a) { document.getElementById("hour").selectedIndex=h; document.getElementById("min").selectedIndex=m; document.getElementById("am").selectedIndex
java script - Ajax
(){ CommonService.getAmount(document.getElementById("pitems").value , populateAmount); } function populateAmount(data){ document.getElementById("amount").value=data...: function getValue(){ var combo = document.getElementById("sel
Vendor Info Error - WebSevices
== 6 || pmMode ==1 || pmMode ==2 || pmMode =="" ) { document.getElementById... || pmMode ==""){ document.getElementById('vendorInfo').style.display="none"; } else { document.getElementById('vendorInfo').style.display="inline
How to retrieve data from database by using combo box value in jsp? - JSP-Servlet
; } function showEmp(emp_value) { if(document.getElementById("emp_id").value..."); } } function stateChanged() { document.getElementById("ename").value =""; document.getElementById("emp_id").value =""; if (xmlHttp.readyState==4
javascript - Development process
next(){ var name=document.getElementById("name").value; if(name=="roseindia"){ document.getElementById("next").href="hello.html"; } } Enter Valid Name
jsp - JSP-Servlet
=="Others"){ document.getElementById('text').disabled = false; } else{ document.getElementById('text').disabled = true; } } A B C D E Others
drodown - JSP-Servlet
= document.getElementById("sel"); var val = combo.options[combo.selectedIndex].text document.getElementById('val').value=val; } <--Select--> Alto Nano
dropdown - JSP-Servlet
??? function getValue(){ var combo = document.getElementById("sel"); var val = combo.options[combo.selectedIndex].text document.getElementById('val').value=val
Clear the print button after onclicking the print - JSP-Servlet
: function hideImage() { if (document.getElementById) { document.getElementById
programming err - JSP-Servlet
. 1) function function1() { document.getElementById("text2").value=document.getElementById("text1").value; } 2
dropdown - JSP-Servlet
: function showEmp(emp_value){ if(document.getElementById("address..."); } } function stateChanged(){ document.getElementById("email").value =""; document.getElementById("address").value =""; if (xmlHttp.readyState==4
java script - Ajax
(){ CommonService.getAmount(document.getElementById("pitems").value , populateAmount); } function populateAmount(data){ document.getElementById("amount").value=data
java program - Java Beginners
jsp code: function show(){ document.getElementById('x').style.visibility='visible'; } function hide(){ document.getElementById('x
Ajax - Ajax
; } function showEmp(emp_value) { if(document.getElementById("emp_id").value... Employee Id"); } } function stateChanged() { document.getElementById("ename").value =""; document.getElementById("emp_id").value
Radio button in JSP - JSP-Servlet
Document function show() { document.getElementById("txtId").style.display='block'; } function hide() { document.getElementById("txtId
htmlcode problem - Java Beginners
generateRow(){ var d=document.getElementById("div"); d.innerHTML+=""; numLinesAdded++; if(numLinesAdded>=4){ document.getElementById
images - JDBC
); document.body.appendChild(div) if (document.getElementById) { document.getElementById
How to get the values from the Combo Box - JSP-Servlet
; } function showEmp(emp_value) { if(document.getElementById("emp_id...() { document.getElementById("ename").value =""; document.getElementById("emp_id").value...(":"); if(strar.length==1) { document.getElementById("emp_id").focus(); alert("Please
html dropdownlist code - JSP-Servlet
].value; if(selItem=="Others"){ document.getElementById('text').style.visibility = 'visible'; } else{ document.getElementById('text').style.visibility
How to make a button of different behaviour?
of SAVE button will call ajaxInsertUpdateData(document.getElementByID("btnSave... ajaxInsertUpdateData(document.getElementByID("btnSave1").value,......); How to do
Hide show HTML forms using javascript
) { document.getElementById('yourDiv').style.display = 'block'; } else { document.getElementById('yourDiv').style.display
How can I do it? .click();
How can I do it? .click();  I have a very unusual problem. I want to make a script like this: <script> x = document.getElementById...: <script> x = document.getElementById("a"); x.mouseup(); </script>
How to set left and top positions of alert box using JQuery in the below code?
() { if(document.getElementById("faxNoId").value=="- -"){ var show=document.getElementById("add"); var hide=document.getElementById("edit... customers=document.getElementById("faxNoId").value; var hide
 

 

 

DMCA.com