www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 27 of 27

Thread: Interesting complex textarea issue

  1. #16
    Join Date
    Nov 2008
    Location
    Akron, OH
    Posts
    233
    on my way out to my daughter's basketball game.
    will pick this up later tonight.

    jwd
    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."

  2. #17
    Join Date
    Dec 2008
    Posts
    14

    Thumbs up

    Ok,

    here is my second page. Instead of returning to the first page, I need to insert it into the db from here.

    Code:
    if (test == 1) {
    var x = data.split(/\+/g);
    	while((newmsg+x[m]).length<41){
    			newmsg=newmsg+x[m]+" ";
    			m++;
    		}
    		var insertSQL="INSERT INTO WHATEVER";  //insert newmsg here and the count of 40 char lines, we will call it i.
    		cnConn.Execute(insertSQL);
    		Response.Write("I should be working");
    		i++;
    
    }
    Thanks for your help!

  3. #18
    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!

  4. #19
    Join Date
    Nov 2008
    Location
    Akron, OH
    Posts
    233
    just got in. are you familiar with the javascript function remove()?
    question: due to db issue will you need to insert each chunk independently and you will need to identify the common key that will allow the 'windows app' you referred to yesterday to identity and retrieve all the msg parts into a unified display. Am I making sense?
    Last edited by javawebdog; 12-09-2008 at 07:59 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."

  5. #20
    Join Date
    Dec 2008
    Posts
    14
    Never heard of remove. I have heard of replace though.

  6. #21
    Join Date
    Nov 2008
    Location
    Akron, OH
    Posts
    233
    Oops! sorry mixing my languages again.
    the trick would be to use a regular Expression to compare the captured chunk (newmsg) to the original string (msg) and using replace() the clear out the captured bit and leave behind the unprocessed bit which in turn is then reprocessed. From a coding modularity pov I would write a separate function to do this, just the keep these apart and adaptive.
    Ignore quoted bit above - brain fade:
    We are working with an array. So once we have determined which elements of the initial array we are using to build the first string chunk we need to get the original array (msg) and remove the elements used. I think this is leading to using the array method splice() to pull out the already processed parts and then we can reprocess the array to get this next chunk.

    Whew! need some coffee ..
    Last edited by javawebdog; 12-09-2008 at 08:54 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."

  7. #22
    Join Date
    Dec 2008
    Posts
    14
    Whew! I can't figure it out.

    Here is what I am wanting to do with the insert:
    Code:
    for (var i = 0; i < myArray.length; i++) {
    		var insertSQL="INSERT INTO SOMETHING(DATA, LINE) VALUES ('myArray[i] +"','"+ i +"')";
    		conn.Execute(insertSQL);
    Help. My brain is about ready to fry....

    I am working with the code that you gave me but inserting each return that I get into an array so that I can then insert each line into the DB.

  8. #23
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,773
    PHP Code:
    var insertSQL="INSERT INTO SOMETHING(DATA, LINE) VALUES ('myArray[i] +"','"+ i +"')"; 
    With a little syntax highlighting you'll see the myArray[i] in your code is actually part of the SQL string, and is not being evaluated by JavaScript. You want to end the quote, put the JavaScript var, then begin the quote again:
    PHP Code:
    var insertSQL="INSERT INTO SOMETHING(DATA, LINE) VALUES ('"+myArray[i]+"','"+"')"

  9. #24
    Join Date
    Nov 2008
    Location
    Akron, OH
    Posts
    233
    you appear to be in good hands with tiocontien
    I haven't worked out all the loops and recursion (you seem to have that ) but here is a bunch of javascript functions that may or may not be useful.

    Code:
    <script>
    var msg="";
    var newmsg="";
    var m=0;
    var leader="";
    var lines_array=[];
    
    //get the textarea content, clip off the key and =, split into an array of whole word. If a word is followed by any punctuation it will be included in the word.
    function getQueryString(){
    msg = window.location.search;
    msg = msg.substring(1);
    msg = msg.split("=");
    msg = msg[1].split(/\+/g);
    }
    
    //process msg to find and isolate the chunk
    function buildInsertStr(msg){
    		while ((newmsg+msg[m]).length<41){
    			newmsg=newmsg+msg[m]+" ";
    			m++;
    		}	
    return newmsg;
    }
    
    //strip off the last captured chunk
    function removeLeaderStr(){
    msg.splice(0,m);
    return msg;
    }
    
    //insert last captured chuck in a new array called lines_array
    function buildInsertArray(newmsg){
    lines_array.push(newmsg);
    }
    
    
    function buildDBInsert(){
    //msg_array is input after all the others function has recursed through the array to words to create and array of string where: each x is one of them
    
    }
    
    </script>
    Last edited by javawebdog; 12-09-2008 at 10:57 AM. Reason: spellling correction
    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."

  10. #25
    Join Date
    Nov 2008
    Location
    Akron, OH
    Posts
    233

    Working code ... (tested in FF3 and IE 7)

    Everything except the INSERT statement ....
    Left a document.write in my buildDBInsert just for demo.
    Code:
    <html>
    <head>
    <script>
    var msg="";
    var currmsg="";
    var newmsg="";
    var m=0;
    var leader="";
    var lines_array=[];
    
    //get the textarea content, clip off the key and =, split into an array of whole word. If a word is followed by any punctuation it will be included in the word.
    function getQueryString(){
    msg = window.location.search;
    msg = msg.substring(1);
    msg = msg.split("=");
    msg = msg[1].split(/\+/g);
    currmsg=msg;
    
    buildInsertStr(currmsg);
    }
    
    
    
    //process msg to find and isolate the chunk
    function buildInsertStr(currmsg){
    
    		while ((newmsg+currmsg[m]).length<41){
    			newmsg=newmsg+currmsg[m]+" ";
    			m++;
    		}
    
    buildInsertArray(newmsg);
    }
    
    //insert last captured chuck in a new array called lines_array
    function buildInsertArray(newmsg){
    
    lines_array.push(unescape(newmsg));
    removeLeaderStr();
    }
    
    //strip off the last captured chunk
    function removeLeaderStr(){
    currmsg.splice(0,m);
    	if(currmsg.length>0){
    	m=0;
    	newmsg="";
    	buildInsertStr(currmsg);
    	}else{
    	buildDBInsert();
    	}
    }
    
    
    function buildDBInsert(){
    //msg_array is input after all the others function has recursed through the array to words to create and array of string where: each x is one of them
    	for (var i = 0; i < lines_array.length; i++) {
    		//var insertSQL="INSERT INTO SOMETHING(DATA, LINE) VALUES ('"+lines_array[i]+"','"+ i +"')"; 
    		
    		document.write(lines_array[i]+"<br />");
    	}
    
    }
    
    </script>
    </head>
    <body>
    <script>
    getQueryString()
    </script>
    
    </body>
    </html>
    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."

  11. #26
    Join Date
    Dec 2008
    Posts
    14
    Awesome!! javawebdog, I actually got everything working before you posted your last items. I just want to Thank You! for all of your help, without it I probably wouldn't have been able to accomplish this. But now I am getting a lot better at Javascript, which could be dangerous. LOL

    Off topic, I live in south-eastern ohio. I am glad someone else in ohio was able to help me out.

  12. #27
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,773
    Quote Originally Posted by jpasswaters View Post
    ... Off topic, I live in south-eastern ohio. I am glad someone else in ohio was able to help me out.
    Yeah. I think there's only one more person on the forums from Ohio. We're a pretty small crowd, but we just increased in size by 50%

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