Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 16th, 2006, 04:27 PM
Friend of Wrox
 
Join Date: Nov 2004
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;
 
Old June 17th, 2006, 07:36 AM
Friend of Wrox
 
Join Date: May 2004
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

 
Old June 20th, 2006, 03:11 PM
Friend of Wrox
 
Join Date: Nov 2004
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 + "\" >";
      }
  }





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





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