Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 16th, 2006, 04:27 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default Changing maxlength in JScript

I have
Code:
    . . .

    if (document.all["ALT_NUM"].size == 6)
    {
        document.all["ALT_NUM"].size      = 9;
        document.all["ALT_NUM"].maxlength = 8;
    }
    else
    {
        document.all["ALT_NUM"].size      = 6;
        document.all["ALT_NUM"].maxlength = 5;
    }

    . . .

</script>
<body>
    . . .

    <input type="text" name="ALT_NUM"
           size="6"    maxlength="5">
    . . .


(Obviously I'm showing fragments . . .)
When the code runs, I get the toggling of the size, but the input limit remains at 5 characters.

So. The question:

    How can the maxlength of a text input be changed through JScript?

I had equally fruitless results with
Code:
   document.all["ALT_NUM"].style.maxlength = 5;
Reply With Quote
  #2 (permalink)  
Old June 17th, 2006, 07:36 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Brian,

This should do it:

document.getElementById("Whatever").setAttribute(' maxlength', 5)

Cheers
Joe

Reply With Quote
  #3 (permalink)  
Old June 20th, 2006, 03:11 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Sorry Joe, I'm afraid that didn’t do the trick either.
What did wind up working though is the following:
Code:
  function Func_3()
  {
      var Value = document.all["ALT_NUM"].value;
      if (document.all["ALT_NUM"].size == 6)
      {
          document.all["ALT_NUM"].outerHTML = "<input name      = \"ALT_NUM\"        " 
                                            + "       size      = \"9\"              " 
                                            + "       maxlength = \"8\"              " 
                                            + "       value     = \"" + Value + "\" >";
      }
      else
      {
          document.all["ALT_NUM"].outerHTML = "<input name      = \"ALT_NUM\"        " 
                                            + "       size      = \"6\"              " 
                                            + "       maxlength = \"5\"              " 
                                            + "       value     = \"" + Value + "\" >";
      }
  }
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VB .Net TextBox MaxLength Mocha Visual Studio 2005 1 October 10th, 2007 08:35 AM
textbox MaxLength akumarp2p C# 2005 1 December 27th, 2006 06:31 AM
maxLength property crmpicco HTML Code Clinic 2 July 7th, 2005 06:53 AM
textbox cutting off text? but maxlength is 10,000? ALEX_GRIM Classic ASP Basics 3 February 6th, 2005 08:47 AM
textbox Maxlength problem ashu_gupta75 Classic ASP Basics 5 May 6th, 2004 03:48 AM



All times are GMT -4. The time now is 08:20 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.