473,624 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Set the maximum value for text box.

36 New Member
Code:
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2.     function setMaximumValue(txtObj, maxVal){
  3.         var tempVal = parseFloat('' + txtObj.value)
  4.         window.event.returnValue = (tempVal <= maxValue);
  5.     }
  6. </script>
  7. <form name="frmSample>
  8.     <input type="text" id="txtAmount" name="txtAmount" value="" 
  9.         onkeypress="setMaximumValue(this, 100.00)">
  10. </form>
Description:
Assume i will enter only numeric to text mox.
Here i want to set maximum value for the control txtAmount.
The maximum value can be numeric, decimal.

But here the keypress event is triggered, then typed character getting updated to "txtAmount" .

So what is the wright way to make this functionality.
Sep 28 '07 #1
3 8592
dmjpro
2,476 Top Contributor
Code:
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2.     function setMaximumValue(txtObj, maxVal){
  3.         var tempVal = parseFloat('' + txtObj.value)
  4.         window.event.returnValue = (tempVal <= maxValue);
  5.     }
  6. </script>
  7.  
Expand|Select|Wrap|Line Numbers
  1. <form name="frmSample>
  2.     <input type="text" id="txtAmount" name="txtAmount" value="" 
  3.         onkeypress="setMaximumValue(this, 100.00)">
  4. </form>
Description:
Assume i will enter only numeric to text mox.
Here i want to set maximum value for the control txtAmount.
The maximum value can be numeric, decimal.

But here the keypress event is triggered, then typed character getting updated to "txtAmount" .

So what is the wright way to make this functionality.
Use Code Tags.
It's not working :-)

Kind regards,
Dmjpro.
Sep 28 '07 #2
pbmods
5,821 Recognized Expert Expert
Heya, getmeidea.

Please use CODE tags when posting source code:

[CODE=javascrip t]
JavaScript code goes here.
[/CODE]
Sep 28 '07 #3
lakshmikamsala
1 New Member
Check this code, it is working fine..

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     function setMaximumValue(id,maxVal){
  3.         var txtObj=document.getElementById(id).value;
  4.         var tempVal = parseInt(txtObj);
  5.         if(tempVal>maxVal)
  6.         {
  7.             alert("Value cannot be taken");
  8.             document.getElementById(id).select();
  9.             document.getElementById(id).focus();
  10.         }
  11. //        window.event.returnValue = (tempVal <= maxVal);
  12.     }
  13. </script>
  14. <form name="frmSample">
  15.     <input type="text" id="txtAmount" name="txtAmount" value="" onkeyup="setMaximumValue(this.id,100.00)">
  16. </form>
Moderator Note: hm, a bit late, I think
Jul 21 '10 #4

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

Similar topics

1
1918
by: K. Davis | last post by:
I need to increment the maximum value of a field of a table by 1 when a form opens a blank record. (e.g. =max(!![trip_number}) so the logic and references are working at the form level. I've tried a number of variants tied to the before update event, but always get the message "The field 'tripmain.trip_number' can't contain a Null value because the Required property for this field is set to True. Enter a value in this field."
5
2699
by: Sunny123 | last post by:
hello i am trying to find the maximum value of a function and where it occur. i.e there is an array x |y ============= | |
29
5086
by: garyusenet | last post by:
I'm trying to investigate the maximum size of different variable types. I'm using INT as my starting variable for exploration. I know that the maximum number that the int variable can take is: 65,535. But i'm trying to write a program to test this, assuming I didn't know this number in advance. I came up with the following but have two questions. Maybe someone can help? using System; using System.Collections.Generic; using System.Text;
3
17918
by: Madmartigan | last post by:
Hello I have the following task but am battling with the final output. How do I keep two different vectors in sync and how would I retrieve the index for the maximum value of one of the vectors?? (using Dev-C++ compiler) Please see task and attempt below: TASK : 1.8.1 Exercise 1A - Temperature tracker Write a program that tracks temperatures during an experiment that takes 24 hours. The user should input the temperature. This...
2
3379
by: Pugi! | last post by:
hi, I am using this code for checking wether a value (form input) is an integer and wether it is smaller than a given maximum and greater then a given minimum value: function checkInteger(&$value, $checks) { $err = ''; if (!is_numeric($value) || (floatval($value) != intval($value))) { $err .= 'Input must be an integer. ';
6
10665
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I'm using the VScrollBar and set it as follow: m_vScrollBar.Minimum = -19602; m_vScrollBar.Maximum = 0; m_vScrollBar.SmallChange = 1; m_vScrollBar.LargeChange = 1089; m_vScrollBar.Value = m_vScrollBar.Maximum; The scroll bar is set to start from the bottom.
4
2853
by: Manikandan | last post by:
Hi, I'm working with XML serialization. I'm writing a xml file of huge size(above 500MB) I need to show the user the progress of writing to file using progress bar. For this i need to create a thread and first start the thread and then writing process, after writing to file stop the thread My doubt is how to set the value for progress bar, some times file size is 100MB and some other time 2GB like, I don't know how to set the progress...
0
1531
by: Fredrik Lundh | last post by:
maurizio wrote: What kind of file is it? Did you pick numpy because you want to do matrix operations (beyond just finding a maximum value), or was it just the first thing you stumbled upon when researching the problem? A simple pattern for finding the maximum value in a file, using only plain Python code, is:
1
3362
by: maurizio | last post by:
thank you for your answer actually i've to do some statistics (maximum,minimum,mean,standard deviation,....) of a file of data in which each column is a particular type of data. (the file is a tab separated value). I was trying to do this by using python (usually i work with fortran or bash, but i'm learning python), that the reason why i tried to use numpy. Fredrik Lundh wrote:
0
8242
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8629
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7170
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...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4084
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
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1793
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1488
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.