Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Feb 2012
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Split TextBox Words into characters

    I have a Text Box which i wish to Place Words into it, once i click the Button it should Split the Words into Characters

    E.G
    I enter Before in Text box it should Should

    B
    E
    F
    O
    R
    E

    Code:
    <script language="javascript">
    
    function getTag(){
    	
    var string = document.getElementById("tag");       
    var array = string.getElementById("tag");
    var finishedArray = [];
    for (var i = 0, il = array.length; i < il; i++) {
      var temp = array[i].getElementById(",");
      for (var j, jl = temp.length; i < jl; j++) {
        finishedArray.push(temp[j]);
    	destLayer = document.getElementById('splitResponse');
    destLayer.innerHTML='';
      }
    }
    
    }
    </script>
    
    
    	<h3>Sentence Splitter</h3>
    
    			<input name="tag" type="text" id="tag" size="30"  autocomplete="off"/>
                <button onClick="getTag();" value="Click"/>Click</button>
    
    			  <div id="splitResponse"></div>
    			  <div class="section"></div>
    			</div>
    Last edited by jace_co_uk; 03-26-2012 at 08:11 AM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Despite the similar sounding names, Java is not the same as Javascript.
    Moving from Java forum to Javascript forum.

  • #3
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,087
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb

    I'm not sure what you 'section' <div> area is about, but this should accomplish the initial request.
    Code:
    <!DOC HTML>
    <html>
    <head>
    <title> Untitled </title>
    <script language="javascript">
    
    function getTag(){
     var arr = document.getElementById("tag").value.split('');
     document.getElementById('splitResponse').innerHTML = arr.join('<br>');
    }
    
    </script>
    </head>
    <body>
    <h3>Sentence Splitter</h3>
    <input name="tag" type="text" id="tag" size="30"  autocomplete="off"/>
    <button onClick="getTag();" value="Click"/>Click</button>
     <div id="splitResponse"></div>
     <div class="section"></div>
    </body>
    </html>

  • Users who have thanked jmrker for this post:

    jace_co_uk (03-26-2012)

  • #4
    New Coder
    Join Date
    Feb 2012
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts
    the
    <div id="splitResponse"></div> is meant to show the content of the split Values inside the text box the rest of the divs are part of the site

    You Code Works Well Thanks alot
    Last edited by jace_co_uk; 03-26-2012 at 06:17 PM.

  • #5
    New Coder
    Join Date
    Jun 2008
    Posts
    62
    Thanks
    0
    Thanked 12 Times in 12 Posts
    ???
    Maybe i don't understand what exactly you mean.
    PHP Code:
    //This is the element contains the word
    <div id="theword">I am the word</div>
    //This element shows teh characters
    <div id="ch"></div
    <
    script type="text/javascript">
    window.onload=function(){
       var 
    string=document.getElementById('theword').innerHTML;
       var 
    characters=string.split('');
       
    document.getElementById('ch').innerHTML='';
       for(var 
    i=0i<characters.lengthi++){
             
    document.getElementById('ch').innerHTML+=characters[i]+'<br>';
       }
    }
    </script> 

  • #6
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,087
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Thumbs up

    Quote Originally Posted by jace_co_uk View Post
    the
    <div id="splitResponse"></div> is meant to show the content of the split Values inside the text box the rest of the divs are part of the site

    You Code Works Well Thanks alot
    You're most welcome.
    Happy to help.
    Good Luck!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •