Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    May 2004
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need some help with text/forms/pastin

    I am writing something where the user can submit something in a form and send it off to a database. I want the text in the form to be broken off and put into another form if it ever goes past a certain length. example: Person is typing in form A and once he hits his 200th character, his 201st will be in the next box. Now with the help of some nice people I was able to get this far, but there have arisen 2 problems.

    1. If you paste a document that is larger than the size you want to cut in half at, the javascript doesnt work.

    2. If you have a limit of say 5 characters, and type in 4 then hit enter you can type in as many as you want, the script stops working.

    Here is the code I have developed with the help of others.

    Code:
    %{
    ###########################################################
    HTML Call_addnews	This is the main section where news is
    ###########################################################
    %}
    %DEFINE{
    	c1="500"
    	c2="500"
    %}
    %HTML(Call_addnews) {
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb">
    <head>
    <meta http-equiv="Content-type" content="text/html; charset=US-ASCII" />
    <link rel="stylesheet" href="master_style.css" type="text/css">
    <script type="text/javascript">
    
    
    function check_length_refocus(txt1, len, txt2) {
     if(txt1.value.length == len) { 
    document.getElementById(txt2).focus(); 
                                             } 
    }  
    
    function gettSelection(ta)
      { var bits = [ta.value,'','','']; 
        if(document.selection)
          { var vs = '#$%^%$#';
            var tr=document.selection.createRange()
            if(tr.parentElement()!=ta) return null;
            bits[2] = tr.text;
            tr.text = vs;
            fb = ta.value.split(vs);
            tr.moveStart('character',-vs.length);
            tr.text = bits[2];
            bits[1] = fb[0];
            bits[3] = fb[1];
          }
        else
          { if(ta.selectionStart == ta.selectionEnd) return null;
            bits=(new RegExp('([\x00-\xff]{'+ta.selectionStart+'})([\x00-\xff]{'+(ta.selectionEnd - ta.selectionStart)+'})([\x00-\xff]*)')).exec(ta.value);
          }
         return bits;
      }
    
    function matchPTags(str)
      { str = ' ' + str + ' ';
        ot = str.split(/\[[B|U|I].*?\]/i);
        ct = str.split(/\[\/[B|U|I].*?\]/i);
        return ot.length==ct.length;
      }
    
    function addPTag(ta,pTag)
      { bits = gettSelection(ta);
        if(bits)
          { if(!matchPTags(bits[2]))
              { alert('\t\tInvalid Selection\nSelection contains unmatched opening or closing tags.');
                return;
              }
            ta.value = bits[1] + '<' + pTag + '>' + bits[2] + '</' + pTag + '>' + bits[3];
          }
      }
    </script>
    </head>
    
    <body bgcolor="#FFFFFF" bgcolor="#FFFFFF" onLoad="javascript:checkUser($(employeeid))">
    <h3><center>Post News</center></h3>
    <hr>
    <form name="NewJobForm" method="post" onSubmit="return validate(this)" action="Call_inputnewsDatabase">
      <div align="center">
        <table width="@dtw_radd(c1, c2)" border="3" cellspacing="1" cellpadding="1" bordercolor="002d64">
    
        <tr> 
            <td width="$(c1)"><b><font size="-1">News Title:</font></b></td>
            <td width="$(c2)"> 
              <input type="text" name="newsTitle" value="">
            </td>
          </tr>
    
          <tr> 
            <td width="$(c1)"><b><font size="-1">Poster:</font></b></td>
            <td width="$(c2)"> 
              <input type="text" name="posterName" value="">
            </td>
          </tr>
    
    	
    	
    	<tr> 
            <td width="$(c1)"><b><font size="-1">Date Posted:</font></b></td>
            <td width="$(c2)"> 
              <input type="text" name="datePosted">
            </td>
          </tr>
    
    	<tr> 
            <td width="$(c1)"><b><font size="-1">Story:</font></b></td>
            <td width="$(c2)"> 
              <textarea rows=5 cols=60 name="Description" wrap = "soft" onkeypress="check_length_refocus(this, 5, 'Description2');"></textarea>
            </td>
          </tr>
    	<tr>
    	<td width="$(c1)"><b><font size="-1">Story Continued</font></b></td>
          <td width="$(c2)">
          <textarea rows=5 cols=60 name="Description2" wrap = "soft" onkeypress=""></textarea>        </td>
          </tr>
    
    	<tr>
    	  <td width="$(c1)"><b><font size="-1">Display Story?:</font></b></td>
    	  <td>
    		Yes<input type="radio" name="Display" value="1" checked> No <input type="radio" name="Display" value="0">
    	  </td>
    	</tr>
    	</table>
    
        <p><input type="submit" value="Post News"> 
             <input type="reset" value="Reset"></p>
         
      </div>
    <input type="hidden" value="$(employeeid)" name="employeeid">
    <input type="hidden" value="$(user_type)" name="user_type">
    </form>
    %include "$(includePath)footer.gfe"
    </body>
    </html>
    %}
    %{\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/%}
    I think I properly highlighted the areas of importance, and if not then the areas of importance are surrounded by [Color][/Color]

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In addition to onkeypress, try also calling your check_length_refocus function onchange, onkeyup and onblur. IE also supports onpaste which will be ignored by other brwsers.

  • #3
    New Coder
    Join Date
    May 2004
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Nope

    didnt work I've been looking all over having a hard time findin the answer

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Simply saying it doesn't work doesn't help us understand your problem. What exactly doesn't work? The focus doesn't change or the text is not split or both?

    The check_length_refocus function you highlighted only changes the focus and I do not even see where you are calling the gettSelection function.

  • #5
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    BTW: This: if(txt1.value.length == len) {

    Says if txt1 value length is equal to the length arguement.
    Change that to more than: if(txt1.value.length > len) {

    Additionaly, it is best to post the rendered code not the generated code.

  • #6
    New Coder
    Join Date
    May 2004
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    thanks will

    Ill check it out and get back just wanted to say that I appreciate your help. Ill be back in tomorrow so if I say anything it will be by then. The problem I'm having is the following:

    Im trying to make an automatic news submission system that a user can log into type up stuff an its entered into a database. Then the database is accessed by another macro which generates a webpage which contains the story. The tricky part is that I have to do this using java and net.data. The problem i've gotten to is the people im doing this for want me to be able to wrap the text around an image. Theres no easy way to do this, to my knowledge. The only thing I could think of is to have 3 tables. 1 for the first column of text, then the next for the picture, and then the last one under the picture, parallel to the first column. This would be similar to most news articles one reads. The reason for the split tables is that I can then divide the news submitted into different strings and display them in the tables separately. Thats why i'm trying todo what i am doing. Its the only way I see the system being more automated. I'll settle for a system where if people are typing in and they hit the limit for the first table they immediately start entering data for the other table. What I'd prefer though is if they could just type the whole news post in one big document and then paste that into a box which automatically splits the info into the two forms. Thats where I'm at now :/


  •  

    Posting Permissions

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