473,664 Members | 3,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

maxlength of textbox is not working in javascript

1 New Member
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 3042
epots9
1,351 Recognized Expert Top Contributor
when does that javascript get executed?
Sep 4 '07 #2
pbmods
5,821 Recognized Expert Expert
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 Recognized Expert Moderator MVP
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
11440
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 button), I can still only enter at most 5 characters into the textbox. So how can I reset the textbox to allow unlimit text to be entered?
1
466
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 typed into this TextBox?
4
8158
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 textbox not support maxlength? How can I make the work? TIA
3
5044
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 Textbox and run a CLientSideFunction. now i was making this clientsidefunction generic so that i can validate all the other textboxes also. Now to do this i need the access to the MaxLength Property, which i am not able to read in the Java...
10
3657
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
6554
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 MaxLength of a TextBox to this value? Thanks, The Confessor
3
4853
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
1723
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 MultiLine TextBox to 250. I figured the best way to do this would be with a RegularExpressionValidator. For my ValidationExpression I figured I would use: ..{0,250} However, the . does not include the \n character. On the page:
6
8041
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 not <asp:TextBox >............. and some of javascripts are 1-------------------------------------------- <script language="JavaScript">
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7375
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5660
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4185
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4351
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2764
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1759
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.