473,473 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Validation script working on Firefox and Chrome, not working on IE

5 New Member
I have a form for registering some bookings. The problem is that I want to validate the data users enter in this form. All works fine, excepting the booking hours (ready by and closing time).

This is the part of the script that does not work:

Expand|Select|Wrap|Line Numbers
  1. function validate_fields()
  2. {
  3.  
  4. if (document.getElementById("compania").value.length == "0")
  5.     {
  6.     document.getElementById("compania").style.background = "#FD9B80";
  7.     submitOK="false";
  8.     }
  9.  
  10. ...............
  11.  
  12. var data = new String(document.getElementById("data").value);
  13.  
  14.  
  15.  
  16. var month = data[3]+data[4];
  17. var day = data[0]+data[1];
  18. var year = data[6]+data[7]+data[8]+data[9];
  19.  
  20. var ready_h = document.getElementById("ready_h").value;
  21. var ready_m = document.getElementById("ready_m").value;
  22. var close_h = document.getElementById("close_h").value;
  23. var close_m = document.getElementById("close_m").value;
  24.  
  25. var date_hour_ready = new Date(month + "/" + day + "/" + year + " " + ready_h + ":" + ready_m);
  26. var date_hour_close = new Date(month + "/" + day + "/" + year + " " + close_h + ":" + close_m);
  27. var last_booking_hour = new Date (month + "/" + day + "/" + year + " " + "19:00");
  28. var first_booking_hour = new Date (month + "/" + day + "/" + year + " " + "09:00");
  29. var current_date = new Date();
  30.  
  31. if (isNaN(ready_h))
  32.     {
  33.     document.getElementById("ready_h").style.background = "#FD9B80";
  34.     submitOK="false";
  35.     }
  36.  
  37. ...............
  38.  
  39. if ((data_ora_close - data_ora_ready) < 2*60*60*1000)
  40.     {
  41.     document.getElementById("ready_h").style.background = "#FD9B80";
  42.     document.getElementById("ready_m").style.background = "#FD9B80";
  43.     document.getElementById("close_h").style.background = "#FD9B80";
  44.     document.getElementById("close_m").style.background = "#FD9B80";
  45.     alert("Pickup time should be at least 2 hours.");
  46.     submitOK="false";
  47.     }
  48.  
  49.  
  50. if (data_ora_ready <= current_date)
  51.     {
  52.     document.getElementById("ready_h").style.background = "#FD9B80";
  53.     document.getElementById("ready_m").style.background = "#FD9B80";
  54.     //alert("Ready by < closing time");
  55.     submitOK="false";
  56.     }
  57.  
  58. if (data_ora_close > last_booking_hour)
  59.     {
  60.     document.getElementById("close_h").style.background = "#FD9B80";
  61.     document.getElementById("close_m").style.background = "#FD9B80";
  62.     alert("Last pickup time should be 19:00");
  63.     submitOK="false";
  64.     }
  65.  
  66. if (data_ora_ready < first_booking_hour)
  67.     {
  68.     document.getElementById("ready_h").style.background = "#FD9B80";
  69.     document.getElementById("ready_m").style.background = "#FD9B80";
  70.     alert("You cannot register bookings earlier than 09:00");
  71.     submitOK="false";
  72.     }
  73.  
  74.  
  75. if (submitOK=="false")
  76.  {
  77.  return false;
  78.  }
  79.  
  80. }
  81.  
There are a lot of other ifs in that function, but just the last four are the problem. They work only on Firefox and Chrome.

Do you have any idea why on Internet Explorer this does not work?
Apr 23 '10 #1
4 3892
Hotice
5 New Member
I don't know if the problem could be here, but here is the HTML code too:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="js/new_shipment_fields_validation.js"></script>
  2.  
  3. <form action='submit.php' method='post' onsubmit='return validate_fields()'>
  4. ........
  5. <input type='text' name='ready_h' id='ready_h' size='1'>
  6. <input type='text' name='ready_m' id='ready_m' size='1'>
  7. <input type='text' name='close_h' id='close_h' size='1'>
  8. <input type='text' name='close_m' id='close_m' size='1'>
  9. .......
  10.  
  11. <input type='submit' value='Register booking'>
  12.  
Cheers!
Apr 23 '10 #2
gits
5,390 Recognized Expert Moderator Expert
try to make the ids and names different and see whether that helps or not ... i think to remember that having both the same could cause problems with IE ...

kind regards
Apr 23 '10 #3
Hotice
5 New Member
@gits
This does not solve the problem (I have more than 40 elements in that form with the same name and ID. And the only validation that does not work is for booking hours).

But I did the following thing: I added one more line:
alert(date_hour_ready);

Now, when I submit the form, on Firefox an alert message is displayed, with the following text: "Sun Apr 25 2010 14:07:00 GMT+0300 (GTB Daylight Time)". On Internet Explorer, the alert box says just "NaN". What could be the problem?

Many thanks!
Apr 25 '10 #4
Hotice
5 New Member
Problem solved.
For selecting one character of a string, Internet Explorer does not recognize this format: string[2].
So, I replaced
Expand|Select|Wrap|Line Numbers
  1. var day = data[0]+data[1];
with
Expand|Select|Wrap|Line Numbers
  1. var day = data.charAt(0)+data.charAt(1);
Many thanks to all for reading my post.
Apr 25 '10 #5

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

Similar topics

6
by: Kenneth | last post by:
Hello, I'm having some serious problems debugging a script that I'm trying to make work. I'm working on a form where a user can type in a time (in the format of HH:MM), and another script...
8
by: Dominic Tocci | last post by:
I'm searching for a way to use window.open on my web page to open a window in firefox that allows the sidebars to work (bookmarks, history, etc). When I use the following: var...
4
by: earwicker | last post by:
I recently deployed a web application which contains a user registration form with the usual fields: name, address, email, password, etc. Each of the TextBoxes uses a validation control to verify...
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?
4
by: Andre | last post by:
Hi, I have read at many place that .Net 2.0 was suppose to support client-side validation in non-IE Browser. But i've try a very simple validation, and firefox is unable to run it, it works only...
7
by: Tim_Mac | last post by:
hi, using .net 2.0, i have a web form with lots of textboxes, drop-down-lists etc. There are lots of required field validators and regular expression validators. When i click the 'save' button,...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
1
by: nitinp | last post by:
hello, I am trying to validate empty textbox value by javascript in Firefox. It is working fine in IE but not in Firefox. Note - code is for ASP.NET <script runat="server"> protected void...
5
by: cbs7 | last post by:
Hi all I'm a complete newbie to web development and Javascript especially. I've been creating a form for a webpage and have used a validation script gen_validatorv2.js which I downloaded from the...
7
by: mike57 | last post by:
The minimal AJAX script below works in Firefox, but not in IE, Opera, or Chrome. I could use some suggestions or referrals to resources that will help me get the script working in other browsers. ...
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,...
1
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...
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.