Sunday, July 1, 2018

JS:Split a user string

Splitting a user string

<!DOCTYPE html>
<html>
<head>

<style>
body {background-color: pink;}
h2   {color: blue;}
p    {color: red;}
</style>

</head>
<body>
<h2 align=center>Spliting Input Strings</h2>
Input a string: <input type="text"  id="string"><br><br>

<p><span id="split"></span></p><br><br>
<input type="button" onclick="myFunction()" value="Split String">
<script>
function myFunction(){
var inputString=document.getElementById("string").value;
var string = "Central University";
    var result = inputString.split(" ");
    var l =result.length;
    var i;
    var res='[';
    for( i=0;i<l;i++){
    res = res + '" '+result[i]+'" ';
   
    }
        res=res+']';
    document.getElementById("split").innerHTML=res;
    }
</script>
</body>
</html>

output

No comments:

Post a Comment

Sacred Thought

5 May 2024 Hari Om Verse 50-51, chapter two:  In this chapter two Shree krishna explains a simple way of living. Free from desires and void ...