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.
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.
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.
Sounds like an in-house app. Is the browser dictated or do you need multiple browser support, too?
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.
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.
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.
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?
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.
The lines variable above becomes an array. The "newline" variable is equal to either \n or \n\r.
var lines = textarea.value.split(newline);
// loop through lines var, detect string length
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.
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.
Part way there:
the next page:
<!-- generic form send textarea submission to next page querystringreader.html -->
<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">
The second page returns a string less than 40.
msg = window.location.search;
msg = msg.substring(1);
msg = msg.split("=");
msg = msg.split(/\+/g);
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
Last edited by javawebdog; 12-08-2008 at 03:36 PM.
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.
see above, done with a while loop. no mid word break since I deal with each word as a whole string.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread