Britech College | Resources

UPDATES, SOURCE CODES AND LECTURE NOTES

JavaScript Code Snippet

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form>
<label>Input First Value</label>
<input type="text" id="text1" /><br/>
<label>Input Second Value</label>
<input type="text" id="text2" /><br/>
<input type="button" onclick="addthis()" value="ADD

NOW"></input>
</form>

<p id="mytext"> This is a text where it will change once you click

the button</p>
<input type="button" onclick="changethis()" value="CLICK TO CHANGE

THE TEXT"></input>
<script type="text/javascript">
function addthis()
{
var num1=document.getElementById("text1").value;
var num2=document.getElementById("text2").value;
var sum=Number(num1)+Number(num2);
document.write(sum);
}
function changethis()
{
document.getElementById("mytext").innerHTML="I am now the

new TEXT.";
}

}
</script>
</body>
</html>

No comments :

Post a Comment