Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a javascript on my page which works fine in all the browsers except IE 8 or 9 (Haven't checked on other versions.).

After some trial and errors I have found that it appears to be caused by a conflict with the requredfieldValidator as when I removed requredfieldvalidator and script runs OK. Here is my sample code.

(I have used master page)

XML
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript" language="javascript">



    function SetStandards(Conducted, Standard, TargetControl) {

        
        TargetControl.value = Number((Number(Standard.value) / Number(Conducted.value) * 100 * 10) / 10).toFixed(1);

        if (isNaN(TargetControl.value) == true) {
            TargetControl.value = '';
        }

        if (TargetControl.value > 100) {
            alert('Some error message.');
            Standard.focus();
        };

    };
</script>

<asp:TextBox ID="txtTecQua0" runat="server" style="text-align:right"
                onBlur="SetStandards(ctl00_ContentPlaceHolder1_txtTecQua0,ctl00_ContentPlaceHolder1_txtTecQua1,ctl00_ContentPlaceHolder1_txtTecQua2);"
                onFocus="GetHelpText('The number of residual chlorine tests refers to routine tests in the distribution network only!  Tests at the treatment plant shall not be included here.')"
                onKeypress="return isNumberKey(event);"></asp:TextBox>
                <div>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
                    ControlToValidate="txtTecQua0"
                    SetFocusOnError="True" ValidationGroup="check">*</asp:RequiredFieldValidator>
                </div>
                <asp:TextBox ID="txtTecQua1" runat="server" style="text-align:right"
                onBlur="SetStandards(ctl00_ContentPlaceHolder1_txtTecQua0,ctl00_ContentPlaceHolder1_txtTecQua1,ctl00_ContentPlaceHolder1_txtTecQua2);"
                onFocus = "GetHelpText('No. of residual chlorine tests which were in compliance with the relevant standards')"
                onKeypress="return isNumberKey(event);"></asp:TextBox>
                <div>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
                    ControlToValidate="txtTecQua1"
                    SetFocusOnError="True" ValidationGroup="check">*</asp:RequiredFieldValidator>
                </div>
                <asp:TextBox ID="txtTecQua2" runat="server" style="text-align:right" CssClass="DisplayTextbox"

                    onFocus ="GetHelpText('Percentage of residual chlorine tests in compliance with relevant standards. Value is calculated on the basis of reported no. of tests conducted and no. of tests in compliance with relevant standards.')"
                    TabIndex="-1"
                    onKeypress="return isNumberKey(event);"></asp:TextBox>
                <div>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator14" runat="server"
                    ControlToValidate="txtTecQua2"
                    SetFocusOnError="True" ValidationGroup="check">*</asp:RequiredFieldValidator>
                </div>
                <asp:Button ID="btnCheck" runat="server" Text="Check" ValidationGroup="check" />
                <asp:Button ID="btnSave" runat="server" Text="Save" />

</asp:Content>


Any advice please??

Thanks in advance.
Posted
Comments
ZurdoDev 14-May-12 8:17am    
What exactly does or does not happen in IE?
hiren soni 14-May-12 8:46am    
I get an error dialog saying 'ctl00_ContentPlaceHolder1_txtCombil' is undefined. And won't get the desired result. That dialog is depend on browser settings.
ZurdoDev 14-May-12 8:48am    
What line of code causes that error?
hiren soni 14-May-12 8:53am    
Just when blur event fires on both the textboxes.
hiren soni 14-May-12 8:55am    
Just on blur evrnt of both the textboxes. .

1 solution

problem may occurs coz validators maintains anonymous function for onblur event in which its not able to get control which ur sending in parameters..

try by making function without params...
i.e.

function SetStandards() {
       var Conducted = document.getElementById("<%= txtTecQua0.ClientID %>");

       var Standard = document.getElementById("<%= txtTecQua1.ClientID %>");
       var TargetControl = document.getElementById("<%= txtTecQua2.ClientID %>");

       TargetControl.value = Number((Number(Standard.value) / Number(Conducted.value) * 100 * 10) / 10).toFixed(1);

       if (isNaN(TargetControl.value) == true) {
           TargetControl.value = '';
       }

       if (TargetControl.value > 100) {
           alert('Some error message.');
           Standard.focus();
       };

   };


and call it on blur like

onblur="SetStandards();"


hope it will help you. :-)
 
Share this answer
 
Comments
hiren soni 14-May-12 8:48am    
Making function without parameter is really dificult because in this application there are hundreds of same calculations.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900