473,385 Members | 1,553 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,385 software developers and data experts.

Firefox Javascript Issue

I have a problem with the global variable valueValidated when I try the following code in firefox.

I wish to validate a value when either the user leaves the field by using the tab key or if they click on a button. I have defined an onchange function to perform a validation if they change the field then change it and also an onmousedown function on the save button to perform validation then save the value. The user may click on the save button to save the value rather than tab out of the field.

I originally had an onchange and an onclick but the onclick never fired if they clicked on the button.

If you enter an invalid value, I have set the onchange to set a flag (valueValidated), so that the "Invalid Value" message is only displayed once. However, in saveValue, it seems that valueValidated has not been set as it still has a value of false even if it has veen set in checkValue.

I split the example into two files as my original code is split into two files just so it matches the original code. Why does the code not work correctly?

Note: I know that IE6 performs the onmousedown before the onchange and I have been able to change my original code so it works with IE6.

eventTest.html

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3.   <head>
  4.     <title></title>
  5.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  6.     <script type="text/javascript" src="eventTest.js"></script>
  7.   </head>
  8.   <body>
  9.       <label>Enter a value between 1 and 10</label>
  10.       <input id="number" onchange="checkValue(this)" />
  11.       <button onmousedown="saveValue()">Save Value</button>
  12.   </body>
  13. </html>
eventTest.js

Expand|Select|Wrap|Line Numbers
  1. // Indicates if the value has been through the validation process not whether the value is correct
  2. var valueValidated = false;
  3.  
  4. function numberInRange (number)
  5. {
  6.     var numberValid = true;
  7.  
  8.     if (1 > number || 10 < number)
  9.     {
  10.         numberValid = false;
  11.     }
  12.  
  13.     return numberValid;
  14. }
  15.  
  16. function checkValue(numberObj)
  17. {
  18.     // Original checkValue performs additional operations so we can't put it into numberInRange
  19.  
  20.     var numberValid = numberInRange (numberObj.value);
  21.  
  22.     if (false == numberValid)
  23.     {
  24.         valueValidated = true;
  25.         alert ("Number out of range (checkValue), valueValidated = " + valueValidated);
  26.     }
  27. }
  28.  
  29. function saveValue ()
  30. {
  31.     var numberValid = false;
  32.  
  33.     if (false == valueValidated)
  34.     {
  35.         var numberObj = document.getElementById ("number");
  36.  
  37.         numberValid = numberInRange (numberObj.value);
  38.         if (false == numberValid)
  39.         {
  40.             alert ("Number out of range (saveValue), valueValidated = " + valueValidated);
  41.         }
  42.     }
  43.  
  44.     if (false == numberValid)
  45.     {
  46.         valueValidated = false; // Force re-validation if user clicks on Save button again.
  47.         alert ("Save aborted, valueValidated = " + valueValidated);
  48.     }
  49. }
Feb 9 '10 #1
1 1699
Dormilich
8,658 Expert Mod 8TB
line #46, if you set valueValidated to false before alerting …
Feb 9 '10 #2

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

Similar topics

3
by: David Hayes | last post by:
I've made tooltips work in Firefox*, but tooltip doesn't appear at the specified location until the SECOND time that the user passes the mouse over the location with the mouseover event. What I...
45
by: Pat | last post by:
its seems asp.net validation doesn't fire when using FireFox? Tested a page and it doesn't fire. It seems the javascript doesn't fire Any ideas?
6
by: Mark Olbert | last post by:
The doPostBack javascript functioning is not submitting the page when called by linkbuttons (or an autopostback checkbox, for that matter). I'm aware of a problem with Netscape browsers and the...
12
by: Brad | last post by:
Does anyone have any other solutions to the Firefox rendering problems with ASP.NET? I've tried the <browsercaps> web.config trick. It didn't work. Am I overlooking something else? Thanks!
7
by: Coder | last post by:
Hi I have the following code in java script, it is not giving proper output in FIREFOX but running fine in IE... can anybody help me out to make this run in FIREFOX . <script...
4
by: evgenyg | last post by:
Hello ! We have the following situation - when Ajax request is sent what's being returned by the server is usually an XML (which is used for DOM updates) but sometimes it's HTML which is a whole...
8
by: Matt Kruse | last post by:
http://news.zdnet.com/2100-1009_22-6121608.html Hackers claim zero-day flaw in Firefox 09 / 30 / 06 | By Joris Evers SAN DIEGO--The open-source Firefox Web browser is critically flawed in...
6
by: scotty | last post by:
I have a script that loops through an existing table list and prepares each href element node to trigger a function when an image is clicked. The function that will be run passes a property value...
3
by: Velhari | last post by:
Hi all, I was showing the popup while hovering over an element under overflow div. so i am getting top and left of current hovering element to display popup with that top and left position. In IE...
3
by: SAL | last post by:
Hello, I did google this issue and found some stuff related to BrowserCaps section of either web.config or machine.config but it didn't work. It seems that most pages in my webapp are okay but a...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.