Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / February 2006

Tip: Looking for answers? Try searching our database.

Splitting contents of a text box into smaller sizes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Colin - 02 Feb 2006 17:20 GMT
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.Y.M. Wong-A-Ton - 03 Feb 2006 11:33 GMT
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);

---
S.Y.M. Wong-A-Ton

> Hello,
>
[quoted text clipped - 4 lines]
> chunk into another field?  So the end result would be 4 text boxes containing
> 255 characters each instead of one containing 1000.
Colin - 03 Feb 2006 14:35 GMT
That works GREAT! Thank you very very much.

> Add the following function to the code for your form:
>
[quoted text clipped - 35 lines]
> > chunk into another field?  So the end result would be 4 text boxes containing
> > 255 characters each instead of one containing 1000.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.