Results 1 to 2 of 2

Thread: resizing a forms input box..

  1. #1

    Thread Starter
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065

    resizing a forms input box..

    OK, i am writing a search engine script in PHP, but, i am also using quite a bit of javascript, to help lower page transfers as much as possible (IE: Reduce invalid form inputs such as invalid email etc,

    and one of the codes i am using, is this function, to make the description only contain what it is allowed to (how many chars)

    Code:
    <script language="javascript">
    <!-- Hide From Older Browsers
    
    // Check the length of the description length
    function Check_Length(desc, max){
                    // Make the length to a shorter call
    	len = desc.value.length;
                    // Set how many chars to trim the description off at
    	trim = max -1;
    	if (len > max){
                                    // Trim and get the langth again
    		desc.value = desc.value.substring(0, trim);
    		len = desc.value.length;
    	}
                    // refocus the textarea
    	desc.focus();
                    // put the value of how many chars are taken into the input text box
    	addform.length.value = len;
    
                    // Set the text box's size property to how many chars are in the box ( < 10 = 1 | > 9 & < 100 = 2 | > 99 & < 1000 = 3 | > 999 = 4
    	if(len < "10"){
    		addform.length.size = 1;
    	}else{
    		if(len < "100"){
    			addform.length.size = 2;
    		}else{
    			if(len < "1000"){
    				addform.length.size = 3;
    			}else{
    				addform.length.size = 4;
    			}
    		}
    	}
    
    }
    // -->
    </script>
    ok, well the problem i am having, is the size property, this code works, but im guessing its a little in-efficient use of if | else's if wrong,

    i use it on the textarea's description box keypress / change / etc,

    So if someone can help me with the long list of else's cool (is there a function to tell how many chars is in a variable? (new to javascript, and current knowledge is only from what i know in php (supprising how alike they are )

    anyhow's.
    TNX

    <edit>
    The page wiv the script on, if u wanna chk how its being used is:

    http://ew-search.realm-ed.co.uk:88/addlink.php?catid=6
    (Currently the if's | else's are making the typing in the text box really lag out,
    the feature * / *** Char's is just to be able to let the user know how many chars they how left.

    And resizing the size property is to make the look better, (as with leaving it at size=4 all the time makes a really large gap in - between * & / ***

    However: Is there a way to align=right the contents of the input type=text?
    Last edited by wpearsall; Dec 15th, 2002 at 10:37 PM.
    Wayne

  2. #2
    Junior Member Mark3's Avatar
    Join Date
    Aug 2002
    Posts
    26
    To align text in a textbox:

    <input TYPE="text" STYLE="text-align: right;" SIZE="20" VALUE="hello">

    Maybe, you wanna look into this type of resizing bbx?

    http://javascript.internet.com/forms...g-textbox.html

Posting Permissions

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



Click Here to Expand Forum to Full Width