www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 27

Thread: Interesting complex textarea issue

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Posts
    14

    Talking Interesting complex textarea issue

    What I am trying to do is, I have a textarea and I need to have a maximum of 40 characters on one line and I need to be able to read each of those lines to put it into a database. I am limited to 40 characters per field in the db. I currently have the items splitting in the middle of a word and I don't want that to happen.

    Any assistance would be much helpful.

    Thanks,
    --Jesse

  2. #2
    Join Date
    Nov 2008
    Location
    Akron, OH
    Posts
    233
    Could you tell us a bit more about what you trying to do?
    Why are you capturing what seem to be multiple database inserts in one html field (textarea), which you then have to parse?

    Why not use multiple textboxes with a maxlength=40? Then process each as a database insert?

    Not at all sure why your using a textarea here.

  3. #3
    Join Date
    Dec 2008
    Posts
    14

    Talking

    Well the reason I only have a length of 40, is because the backend db can't be reconfigured, it currently transfers the data to a windows app where the lines of the textarea (in the windows app) have a max length of 40 with multiple rows.

    I have a notes section online where people can enter notes and those notes then have to be transfered to the db so that the people on the windows app can read the data.

    Hopefully that makes sense.

    Thanks!

  4. #4
    Join Date
    Nov 2008
    Location
    Akron, OH
    Posts
    233
    Sounds like an in-house app. Is the browser dictated or do you need multiple browser support, too?

  5. #5
    Join Date
    Dec 2008
    Posts
    14
    LOL, I wish it was only single browser support. It has to be compatible with IE and FireFox. I have found that those two don't play well together with the same HTML and CSS.

  6. #6
    Join Date
    Nov 2008
    Location
    Akron, OH
    Posts
    233
    OK. You have an html textarea with no maxlength? you want to submit the content of that to a database in 40 char segments (without word breaks). Tell me a bit more about this 'windows app'. Is the 'windows app' getting data from the database that you have inserted into the db? and the problem is the display in the 'windows app'? or is it the limiting size of the db column?

    I am trying to understand where the limitation is: in the windows app or the db? If in the db do you have a way of building a db key that will pull back all the db rows associated with that key?
    Last edited by javawebdog; 12-08-2008 at 12:22 PM.

  7. #7
    Join Date
    Dec 2008
    Posts
    14
    Maxlength of this text area is 200 characters. Yes, I believe you are understanding it correctly. The windows app can only contain a maximum of 40 chars per line. Each line will get inserted into a separate field in the db.

  8. #8
    Join Date
    Nov 2008
    Location
    Akron, OH
    Posts
    233
    You need to parse the textarea into 1-40 char/line, set each parsed segment up as a db insert, with a common key (say, message_number), which in turn the 'windows app' can retrieve by iteration and load into it's display area. That the problem?

  9. #9
    Join Date
    Dec 2008
    Posts
    14
    Yup. That is correct.

  10. #10
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,774
    When you submit the form, split the textarea value by the "\n" character. You'll first need to detect the newline character type. Opera uses \r\n and Firefox, IE, and I think all others user \n.

    Code:
    var lines = textarea.value.split(newline);
    // loop through lines var, detect string length
    The lines variable above becomes an array. The "newline" variable is equal to either \n or \n\r.

  11. #11
    Join Date
    Dec 2008
    Posts
    14
    Been there and tried that. The problem is I need to split on 40 characters because the letter "l" isn't the same width as the letter "W" and that throws off the character count. Also, the textarea width in IE isn't the same width as in FireFox.

    Great Try though.

  12. #12
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,774
    Once you've got the array of strings, which represent the lines in the text area, test the width of each string in the array. If the width is more than 40 characters, then you'll need to pass that string to a function that splits it up into 40 char pieces.

  13. #13
    Join Date
    Dec 2008
    Posts
    14
    At toicontien:

    If I would happen to do it this way, I would have to split on a <space> before the end of the string. For instance a string could be:

    "This is a test to see if a line will break at 40 chars"

    The line would break in between the e and the a in the word "break". I would need to backtrack 4 chars and then remove the space and replace it with a return string.

    How would you go about doing something like that?
    Last edited by jpasswaters; 12-08-2008 at 03:35 PM.

  14. #14
    Join Date
    Nov 2008
    Location
    Akron, OH
    Posts
    233
    Part way there:
    try these:
    Code:
     
    <!-- generic form send textarea submission to next page querystringreader.html -->
    <html>
    <head>
    
    </head>
    <body>
    <form method="get" action="querystringreader.html">
    <textarea name="txtarea" maxlength=200 cols=40 row=6></textarea>
    <input type="submit" value="GO">
    <input type="reset" value="CLEAR">
    </form>
    </body
    </html>
    the next page:
    Code:
    <html>
    <head>
    <script>
    var msg="";
    var newmsg="";
    var m=0;
    function getQueryString(){
    msg = window.location.search;
    msg = msg.substring(1);
    msg = msg.split("=");
    msg = msg[1].split(/\+/g);
    
    buildInsertStr();
    document.writeln(unescape(newmsg));
    }
    function buildInsertStr(){
    
    		while ((newmsg+msg[m]).length<41){
    			newmsg=newmsg+msg[m]+" ";
    			m++;
    		}		
    return newmsg;
    }
    
    </script>
    </head>
    <body>
    <script>
    getQueryString();
    </script>
    
    </body>
    </html>
    The second page returns a string less than 40.
    The next step is to 'clipped' off the parsed pieces out of the array msg (which is an array of 'words'), and then reprocess the array, etc. unitl we run out of words in the array from the submission in the textarea.

    Works in both IE7 and FF3.04

    Your turn!
    Last edited by javawebdog; 12-08-2008 at 03:36 PM.

  15. #15
    Join Date
    Dec 2008
    Posts
    14
    Ok, how would I go about doing this in the querystringreader.html so that I can insert all of the lines? I guess I want to reprocess the array while I am in querystringreader.html.

    Quote Originally Posted by javawebdog View Post
    The next step is to 'clipped' off the parsed pieces out of the array msg (which is an array of 'words'), and then reprocess the array, etc. unitl we run out of words in the array from the submission in the textarea.

    Works in both IE7 and FF3.04

    Your turn!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles