?
Solved

Custom Validation not firing javascript in FireFox

Posted on 2005-04-04
6
Medium Priority
?
1,849 Views
Last Modified: 2008-01-09
I have created with help from this site, an ASP.NET page that validates numerious textarea fileds for numeric input, If they user enters text instead of a number the error message is to appear and the textarea is to turn light red. Everything works like a charm in IE, but the javascript will not fire in Firefox. Note that I have an alert call at the top of the javascript which is not firing wither so the function itself is never being called. All of the key code snippets are below:


---------javascript ---------------
<script language="javascript">
          function ValidateHours(sender, args) {
             
            alert("testing")
             
              var ivalError = 0;
              if (document.getElementById("txtDrvHrsMon").value-Math.floor(document.getElementById("txtDrvHrsMon").value) == 0)
               {
                              document.getElementById("txtDrvHrsMon").style.backgroundColor = "white";
               }  else
               {
                              document.getElementById("txtDrvHrsMon").style.backgroundColor = "pink";
                              ivalError++              
               }
                                   
               if (ivalError > 0) {                              
                 args.IsValid = false;                        
                 return    
               }else{
                         args.IsValid = true;              
               }
          }
</script>


--------- Control on page -----------------
<asp:textbox id="txtDrvHrsMon" runat="server" Columns="5">0</asp:textbox>


---------- Validation control -----------------
<asp:customvalidator id="valAllHrs" runat="server" Display="Static" ErrorMessage="Hours must be in numeric format."
ClientValidationFunction="ValidateHours"></asp:customvalidator>
0
Comment
Question by:cbittner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13702104
That's because the customvalidaiton control missed(maybe intentionally) several import elements when rendering on Firefox browser. I guess this must be Microsoft's strategy to beat other browsers.
Don't think you can have much to do about it.

A simple solution is to copy the code that are rendered in IE but not in Firefox to the
.aspx file to replace the customvalidation control
0
 
LVL 12

Accepted Solution

by:
laotzi2000 earned 500 total points
ID: 13702203
another solution:
1.get rid of the customvalidation control
2.add the following attribute to form: onsubmit="return ValidateHours();"
3.modify your validation function to as follows:
            <script language="javascript">
          function ValidateHours(sender, args) {
             
           alert("testing")
             
              var ivalError = 0;
              if (document.getElementById("txtDrvHrsMon").value-Math.floor(document.getElementById("txtDrvHrsMon").value) == 0)
               {
                         document.getElementById("txtDrvHrsMon").style.backgroundColor = "white";
               }  else
               {
                         document.getElementById("txtDrvHrsMon").style.backgroundColor = "pink";
                         ivalError++              
               }
                                   
               if (ivalError > 0) {                              
                 return false;                      
             
               }else{
                     return true;
                 
               }
               return false;
          }
            </script>
0
 
LVL 23

Assisted Solution

by:b1xml2
b1xml2 earned 500 total points
ID: 13707103
keep the client validation,

add the server validation
<asp:customvalidator id="valAllHrs" runat="server" Display="Static" ErrorMessage="Hours must be in numeric format."
ClientValidationFunction="ValidateHours_ClientValidate" OnServerValidate="ValidateHours_ServerValidate"></asp:customvalidator>

  <script language="javascript">
  function ValidateHours_ClientValidate(sender, args)
  {
      var valid = isValidHours();
      getHoursElement().style.backgroundColor = valid ? "white" : "pink";
      args.IsValid = valid;
}
         

function getHoursElement()
{
      return document.getElementById("txtDrvHrsMon");
}

function isValidHours()
{
      var el = getHoursElement();
      return (parseInt(el.value) - Math.floor(el.value) == 0);
}
</script>


<script language="VB" runat="server">
Sub ValidateHours_ServerValidate(ByVal sender As Object, ByVal args As ServerValidateEventArgs)
Dim value As Boolean = IsValidHours
txtDrvHrsMon.Style("background-color",CStr(IIf(value,"white","pink")))
args.IsValid = value
End Sub

ReadOnly Property IsValidHours() As Boolean
      Get
            Return (CInt(txtDrvHrsMon.Text) - CType(Math.Floor(CDbl(txtDrvHrsMon.Text)), Integer) = 0)
      End Get
End Property
</script>
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:cbittner
ID: 13711602
I am trying the code b1XML2 added, but I am getting an error because both javascript, and VB are on the same aspx page. Am I missing something obvious? which does seem to be a hobby of mine.
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 13713561
show us what u have and by the way, don't feel down.

In fact because you are trying to understand how things work, you will get there. It is far better to face difficulties when trying to understand rather than being given the solution without trying or wanting to understand. So, a big pat on your back for your efforst.
0
 

Author Comment

by:cbittner
ID: 13727519
I will respond back to this but I had to move to other screens, so I'll be back to this issue in a few DAZE
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month9 days, 12 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question