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 8 of 8
  1. #1
    New Coder
    Join Date
    May 2004
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    A New Challenge~only for pros though :)

    I want to make a script~~~

    I want this script to do the following~~

    I have no clue how to do this ~~~~

    : The Script will be used with a form. If the user is entering text into the form and reaches a limit, say X charcters(300 for example) , the test then automatically goes into a different form box.

    Example:

    I have a Form item called Description:
    Someone writes 300 characters in Description and the second they hit 301st charcter, that character appears in item Description2 and keeps going. Any idea? Anyone brave enough to handle that?

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I though it was supposed to be challenging
    Code:
    <textarea onkeyup="if(this.value.length>300) this.nextSibling.focus();"></textarea><textarea></textarea>
    Try again
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

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

    I have no idea

    No Idea how I would make those functions. I'm obviously a lesser lifeform than you.

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay this is how you'd do it:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    
    <html>
    <head>
    <title>Untitled</title>
    
    <script>
     function check_length_refocus(txt1, len, txt2) {
      if(txt1.value.length == len) {
       document.getElementById(txt2).focus();
      }
     }
    </script>
    
    </head>
    <body>
     <form>
      <textarea id="descr_1" onkeypress="check_length_refocus(this, 5, 'descr_2');"></textarea>
      <textarea id="descr_2" onkeypress=""></textarea>
     </form>
    </body>
    </html>
    If you have troubles applying this to your code, let me know and I'll help adapt it..

    But I think you should stop asking questions in this way: "I've got a challenge for you!!" Like what's up with that man? You want us to do the work for you or what? Throw some paper this way then..

    Google and the search feature on this website are excellent resources. You should research what you're trying to accomplish first, try it, and then if you run into problems you can post them here and we can help you debug them.

    That's just what I think anyway..

    Hope that helps,
    Sadiq.

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

    Angry This May Help

    This is the code I have right now.. Ignore the stuff that you dont understand, its net.data


    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 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];
          }
      }
    
    function addImage(){
    	var img_location= prompt ("write the name of the file after the last '/' , then copy this all and paste it where you want the image","<IMG SRC=http://67.94.110.170/artis_news/images/")
    				     	}
    
    
    function validate(form) {
    	if (form.newsTitle.value == "" || form.newsTitle.value == " ")
    	{
    		alert("Please enter a Job Title")
    		return false
    	}	
    
          if (form.posterName.value == "" || form.posterName.value == " ")
    	{
    		alert("Please enter a value")
    		return false
    	}
    	return true
    
    	if (form.datePosted.value == "" || form.datePosted.value == " ")
    	{
    		alert("Please enter a Date")
    		return false
    	}
    	return true
    
    	if (form.Description.value == "" || form.Description.value == " ")
    	{
    		form.Description.value="NA"
    		return true
    	}
    	return true
    					}
    
    function checkUser(key) {
         if (key == "" || key == " ") {
              location.href = "..//signin.d2w/welcome";}
     }
    
    
    </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"></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"><INPUT TYPE="button" VALUE="Image" onClick="addImage()">
              <button onclick="addPTag(document.getElementById('Description'),'I')"><i>Italic</i></button>
              <button onclick="addPTag(document.getElementById('Description'),'U')"><u>Underline</u></button>
              <button onclick="addPTag(document.getElementById('Description'),'B')"><b>Bold</b></button> </p>
              <button onclick="addPTag(document.getElementById('Description'),'P')">Paragraph</button>
    	    <button onclick="addPTag(document.getElementById('Description'),'CENTER')">Align Center</button>
    	    <button onclick="addPTag(document.getElementById('Description'),'LEFT')">Align Left</button>
    	   <button onclick="addPTag(document.getElementById('Description'),'RIGHT')">Align Right</button>	    
      </div>
    <input type="hidden" value="$(employeeid)" name="employeeid">
    <input type="hidden" value="$(user_type)" name="user_type">
    </form>
    %include "$(includePath)footer.gfe"
    </body>
    </html>
    %}
    %{\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/%}
    Last edited by liorean; 05-27-2004 at 06:39 PM.

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

    ~~and saddiq~~

    I appreciate your help, I guess my question asking method is flawed for 2 reasons. 1. I really DID think these were really hard 2. On this other forum where I used to write a lot of C++ someone else would pose questions like that and it kinda grew on me :/

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It's an easy mistake to make Generally, it's best to avoid subject titles which are leading in some way - titles like "here's a challenge for you experts" and so on, they're cheap psychological tactics - trying to play to people's ego and make someone think "oh well, I'll answer this question to show what an expert I am"

    That's how it comes across anyway, and that gets people's backs up because it's leading, not an open request for help.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #8
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by imiscor
    I appreciate your help, I guess my question asking method is flawed for 2 reasons. 1. I really DID think these were really hard 2. On this other forum where I used to write a lot of C++ someone else would pose questions like that and it kinda grew on me :/
    Ok.. well stop it, it's annoying!

    As for the code you posted, 3 things:
    -wrap it in [ code ] [ /code ] tags, no spaces in there..
    -make sure your code is formatted and readable
    -which textboxes/textareas do you want to apply this 'hit the character limit and refocus' function?

    If you want it on all your text inputs and textareas, here ya go:
    Code:
    ...
    <input type="text" name="newsTitle" value="" id="nTitle" onkeypress="check_length_refocus(this, 20, 'pTitle');">
    ...
    <input type="text" name="posterName" value="" id="pTitle" onkeypress="check_length_refocus(this, 15, 'dTitle');">
    ...
    <input type="text" name="datePosted" id="dTitle" onkeypress="check_length_refocus(this, 10, 'descr');">
    ...
    <textarea rows=5 cols=60 name="Description" wrap = "soft" id="descr" onkeypress="check_length_refocus(this, 300, 'disp');"></textarea>
    ...
    <input type="radio" name="Display" value="1" checked id="disp">
    ...
    If that's not what you want, explain better..

    Sadiq.


  •  

    Posting Permissions

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