Buy Electronics

Saturday, June 26, 2010

Diff getElementById ().value & getElementById ().innerHTML

Example : Updating Text Based on User Input:

Note:
If we want to access the text within a non-input HTML element, then we are going to have to use the innerHTML property instead of value.

<script type="text/javascript">
function changeText()
{
// Get user I/p data
var userInput = document.getElementById (“userInput”).value;

// Get data from non-input element & replace old data
document.getElementById (“boldStuff2”).innerHTML = userInput;
}
</script>

Welcome to the site <b id=“boldStuff2”>dude</b> </p>

<input type=“text” id=“userInput” value=“Enter Text Here” />
<input type=“button” onclick=“changeText ()” value=“Change Text” />

Mobiles