473,395 Members | 1,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

maxlength of textbox is not working in javascript

Hi,
I'm trying to control the maxlength property of a textbox in javascript. But it's not going into effect.This is my code

HTML
Expand|Select|Wrap|Line Numbers
  1. <input type=text id="txt_search_string" class=formtext maxlength=100 />
  2.  
JavaScript
Expand|Select|Wrap|Line Numbers
  1. if(var_selection = 'C')
  2.    document.getElementById('txt_search_string').MaxLength = '6' ;
  3. else if (var_selection = 'D')
  4.    document.getElementById('txt_search_string').MaxLength = '12' ;
  5.  
There's nothing wrong in the syntax as I checked it and there are no errors either. It looks fine except the maxlength going into effect. Your help greatly appreciated.
Sep 4 '07 #1
3 3024
epots9
1,351 Expert 1GB
when does that javascript get executed?
Sep 4 '07 #2
pbmods
5,821 Expert 4TB
Heya, engineer. Welcome to TSDN!

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

Try using
Expand|Select|Wrap|Line Numbers
  1. document.getElementById('txt_search_string').setAttribute('maxlength', 6);
Sep 4 '07 #3
acoder
16,027 Expert Mod 8TB
You could also use the maxLength property.
Sep 4 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Lovely Dola | last post by:
I have set the MaxLength property of a textbox in a form to 5 at design time. When I change the MaxLength back to 0 during run-time under some condition (for example, after clicking a command...
1
by: mg | last post by:
I have a MultiLine TextBox (WebForm - C#) with the MaxLength property = 1000 but am able to type in an unlimited number of characters. Is there a way to limit the number of characters that can be...
4
by: hardcoded | last post by:
I have a textbox with TextMode set to MultiLine. I also have the MaxLength set to 255. This maxlength value seems to get ignored as the user can enter unlimited characters. Does the multiline...
3
by: RSB | last post by:
Hi Everyone, I have this TextBox with the TextMode="MultiLine". so now it does not validate the text in the TextBox for the MaxLength SO i have decided to execute a CustomValidator for this...
10
by: danthman | last post by:
I have a TextBox set up as follows: <asp:TextBox ID="SubjectTextBox" TextMode="MultiLine" MaxLength="100" Columns="50" Rows="2" Wrap="true" runat="server" />
9
by: The Confessor | last post by:
I declare the following variable in one of my structures... <VBFixedString(17)> Dim Name As String Fixed to 17 because it's written to a random-access file. Is there any way to tie the...
3
by: h | last post by:
Hi, I have set my textbox's maxlength property to 1 , however it allow more than one word. Is there any settings that I am missing ? Thanks in advance Hardik Shah
2
by: Nathan Sokalski | last post by:
As we probably know, the MaxLength property of the TextBox control only works when the TextMode property is SingleLine or Password. I want to limit the number of characters a user can enter into a...
6
Coldfire
by: Coldfire | last post by:
I am having problems with Maxlength of Multiline "Textbox". I have browsed alot to find the solution. Tons of javascripts have been found but they all deal with <asp:textarea >............. and...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.