...

View Full Version : Split TextBox Words into characters



jace_co_uk
03-26-2012, 12:36 AM
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




<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>

Fou-Lu
03-26-2012, 02:43 PM
Despite the similar sounding names, Java is not the same as Javascript.
Moving from Java forum to Javascript forum.

jmrker
03-26-2012, 03:04 PM
I'm not sure what you 'section' <div> area is about, but this should accomplish the initial request.


<!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>

jace_co_uk
03-26-2012, 06:08 PM
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

Labrar
03-26-2012, 07:45 PM
???
Maybe i don't understand what exactly you mean.


//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=0; i<characters.length; i++){
document.getElementById('ch').innerHTML+=characters[i]+'<br>';
}
}
</script>

jmrker
03-26-2012, 09:25 PM
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!
:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum