<!DOCTYPE html>
<html>
<body>
<p>Click the button to return the number of characters in the string "Hello World!".</p>
Enter First String: <input type="text" name="txt_fstring" id="first"/> <br/>
Enter Second String: <input type="text" name="txt_sstring" id="second"/> <br/>
<button onclick="myFunction()">Try it</button>
<!--<p id="demo"></p>-->
<script language="JavaScript">
function myFunction() {
var str = document.getElementById("first").value;
var str1 = document.getElementById("second").value;
var n = str.length;
var n1 = str1.length;
//document.getElementById("demo").innerHTML = str +" "+ n +" "+ str1 +" "+ n1;
if(n > n1) {
document.write("First String is larger than Second");
}
else if(n< n1){
document.write("Second String is larger than First");
}
else {
document.write("Both are Same");
}
}
</script>
</body>
</html>
No comments:
Post a Comment