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.
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.
javawebdog Two things to remember:
"The only place success comes before work is in the dictionary."
"It's more than just a matter of survival. It's a matter of sympathy, compassion, passion and style."
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.
Sounds like an in-house app. Is the browser dictated or do you need multiple browser support, too?
javawebdog Two things to remember:
"The only place success comes before work is in the dictionary."
"It's more than just a matter of survival. It's a matter of sympathy, compassion, passion and style."
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 11:22 AM.
javawebdog Two things to remember:
"The only place success comes before work is in the dictionary."
"It's more than just a matter of survival. It's a matter of sympathy, compassion, passion and style."
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?
javawebdog Two things to remember:
"The only place success comes before work is in the dictionary."
"It's more than just a matter of survival. It's a matter of sympathy, compassion, passion and style."
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.
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.
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.
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 02:35 PM.
<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 02:36 PM.
javawebdog Two things to remember:
"The only place success comes before work is in the dictionary."
"It's more than just a matter of survival. It's a matter of sympathy, compassion, passion and style."
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.
Originally Posted by javawebdog
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.
Bookmarks