Splitting contents of a text box into smaller sizes

C

Colin

Hello,

I have a form that contains a text box that users type notes into. The text
box may conatin anywhere from 0 characters to 1000. What I would like to
know is, does anyone know the JScript code that can count the characters in
the large text box, remove 255 characters at a time and place each smaller
chunk into another field? So the end result would be 4 text boxes containing
255 characters each instead of one containing 1000.
 
S

S.Y.M. Wong-A-Ton

Add the following function to the code for your form:

---
function getTextChunk(origText, startPos, chunkLength)
{
if (origText.length >= startPos + chunkLength) {
return origText.substr(startPos, chunkLength);
} else {
return origText.substr(startPos);
}
}
---

Then use it as follows:

---
var longText = XDocument.DOM.selectSingleNode("//my:notes").text;
var chunkLength = 255;

XDocument.DOM.selectSingleNode("//my:field1").text = getTextChunk(longText,
0, chunkLength);
XDocument.DOM.selectSingleNode("//my:field2").text = getTextChunk(longText,
chunkLength, chunkLength);
XDocument.DOM.selectSingleNode("//my:field3").text = getTextChunk(longText,
2*chunkLength, chunkLength);
XDocument.DOM.selectSingleNode("//my:field4").text = getTextChunk(longText,
3*chunkLength, chunkLength);
 
C

Colin

That works GREAT! Thank you very very much.

S.Y.M. Wong-A-Ton said:
Add the following function to the code for your form:

---
function getTextChunk(origText, startPos, chunkLength)
{
if (origText.length >= startPos + chunkLength) {
return origText.substr(startPos, chunkLength);
} else {
return origText.substr(startPos);
}
}
---

Then use it as follows:

---
var longText = XDocument.DOM.selectSingleNode("//my:notes").text;
var chunkLength = 255;

XDocument.DOM.selectSingleNode("//my:field1").text = getTextChunk(longText,
0, chunkLength);
XDocument.DOM.selectSingleNode("//my:field2").text = getTextChunk(longText,
chunkLength, chunkLength);
XDocument.DOM.selectSingleNode("//my:field3").text = getTextChunk(longText,
2*chunkLength, chunkLength);
XDocument.DOM.selectSingleNode("//my:field4").text = getTextChunk(longText,
3*chunkLength, chunkLength);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top