views:

5287

answers:

10

i'm getting an error 'Object expected' for some odd reason due to jquery, and this does not 'submit' the form or enter the data into database.

without jquery, the data could be entered into the database. but now it doesn't.

i've used jquery mainly for validating asp.net controls.

+6  A: 

Object expected occur when you try to access object which is not defined, not referenced or mistakenly misspelled. Check out which object is expected. Use Firefox firebug to debug your javascript or make debugging with IE on to get hold of an object which runtime is not able to find....

Software Enthusiastic
A: 

this is jquery code:

 <script type="text/javascript">
        $(document).ready(function() {
            // add custom validation methods
            $.validator.addMethod('phone', function(value, el, params) {
                return this.optional(el) || /^[0-9,+,(), ,]{1,}(,[0-9]+){0,}$/.test(value);
            }, 'Please enter a valid phone number');

            $.validator.addMethod('numbers', function(value, el, params) {
                return this.optional(el) || /^[0-9]+$/.test(value);
            }, 'Invalid entry. Only Numeric is allowed.');


            $.validator.addMethod('domainurl', function(value, el, params) {
                return this.optional(el) || /^(http\:\/\/(?:www\.)?[a-zA-Z0-9]+(?:(?:\-|_)[a-zA-Z0-9]+)*(?:\.[a-zA-Z0-9]+(?:(?:\-|_)[a-zA-Z0-9]+)*)*\.[a-zA-Z]{2,4}(?:\/)?)$/.test(value);
            }, 'Please enter a valid domain url');


            $.validator.addMethod('selectone', function(value, element) {
                return this.optional(element) || (value.indexOf("none") == -1);
            }, 'Please select an option.');



            $("#form1").validate({
                debug: true,
                rules: {
                    txt_name: {
                        required: true,
                        minlength: 2
                    },
                    txt_cmp: {
                        required: true,
                        minlength: 2
                    },
                    txt_tel1: {
                        phone: true,
                        required: true,
                        minlength: 3

                    },
                    txt_tel2: {
                        phone: true,
                        required: false,
                        minlength: 3

                    },
                    txt_mob: {
                        phone: true,
                        required: false,
                        minlength: 9

                    },
                    txt_email: {
                        required: true,
                        email: true
                    },

                    txt_domname: {
                        required: true,
                        domainurl: true
                    },

                    radiobt_domain: "required",

                    ddl_yremail: {
                        required: true,
                        selectone: true
                    },
                    ddl_email: {
                        required: true,
                        selectone: true
                    },

                    txt_space: {
                        required: true,
                        numbers: true

                    },
                    txt_calfr: {
                        required: true
                    },
                    txt_calto: {
                        required: true
                    }  


            },
            messages: {
                txt_name: {
                    required: "This field is required",
                    minLength: "Please enter a valid name"
                },
                txt_cmp: {
                    required: "This field is required",
                    minLength: "Please enter a valid commpany name"
                },
                txt_tel1: {
                    required: "This field is required",
                    minLength: "Please enter a valid telephone number"

                },
                txt_tel2: {
                    minLength: "Please enter a valid telephone number"
                },
                txt_mob: {
                    minLength: "Please enter a valid mobile number"

                },
                txt_email: {
                    email: "Please enter a valid email address",
                    required: "This field is required"
                },

                txt_domname: {
                    required: "This field is required"
                },
                radiobt_domain: "Select the Hosting Type"
            }

        });
    });
    </script>

is there anything wrong with the code?

it says object expected at line 559. i checked the jquery.validate.js file and this is the code it shows:

addWrapper: function(toToggle) {
      if ( this.settings.wrapper )
       toToggle = toToggle.add( toToggle.parents( this.settings.wrapper ) );
      return toToggle;
     }

the jquery code displays all the errors at the right places, but once corrected, it doesn't submit the data.

fuz3d
i ran the firebug as well as the script debugger. it says:validate is not definedonclick(click clientX=543, clientY=482)0AifAgug...0Wg%3D%3D (line 2)[Break on this error] return validate();i had added return validate() function on the onclick function of btn_submit: <asp:Button ID="btn_submit" runat="server" Text="Submit" style="position: relative; top: 2px; left: 429px" OnClientClick="return validate();" Font-Names="Nyala" Font-Size="14px" />am i doing anything wrong?
fuz3d
Do not post new answers but edit your original question instead.
Török Gábor
A: 

the above comment turned out to be quite messed up. anyway:

i ran the firebug as well as the script debugger. it says:

validate is not defined 
onclick(click clientX=543, clientY=482)0AifAgug...0Wg%3D%3D (line 2) [Break on this error] 
return validate();

i had added return validate() function on the onclick function of btn_submit:

<asp:Button ID="btn_submit" runat="server" Text="Submit" style="position: relative; top: 2px; left: 429px" OnClientClick="return validate();" Font-Names="Nyala" Font-Size="14px" />

am i doing anything wrong?

fuz3d
I dont understand, why are you calling validate() inline ? When you did $('#form1').validate(.... ), isn't that already attaching the event handler to your form submit ? I think I am missing the point
Amit
so, i don't need to call validate()?
fuz3d
Do not post new answers but edit your original question instead.
Török Gábor
A: 

even if i remove validate() from the button control, it doesn't submit the data and doesn't show any error either.

fuz3d
Could you add a link to the documentation on the plug-in you are using?
roosteronacid
this is the link: http://bassistance.de/jquery-plugins/jquery-plugin-validation/
fuz3d
the validations are working quite well. if i click the submit button and if there's an error in the control, then it shows the appropriate errors. but the server-side to enter the data into database is not executing for reasons unknown. neither firebug nor script debugger is detecting any error either.
fuz3d
A: 

My guess is that the error is in your use of the jQuery validation plug-in. Try to validate only one ASP.NET control. This will make the error easier to spot:

$("#form1").validate({
    rules: {
       id_of_control_you_know_exists_in_the_rendered_html: {
            required: true,
            minlength: 2
        }
    }
});

Another possibility could be that you are using ASP.NET controls in a user control. In that case the id-property of the rendered HTML input control is different from what you set it to in your .aspx page.

roosteronacid
A: 

roosteronacid, the validations are working perfectly fine and the id property is also the same. the submit is just not executing the server-side code and i cannot figure out what is the problem.

fuz3d
Do not post new answers but edit your original question instead.
Török Gábor
A: 

answer here: http://stackoverflow.com/questions/827005/submit-button-does-not-trigger-server-side-code

'debug' should be set as false.

fuz3d
A: 

I had the same issue but on our staging server. Comparing files showed they were the same and hosting the exact same files on different sites had no issue so it had to be the specific site we were putting files on. The culprit after troubleshooting was that we set a Footer.html file setting in the properties for the website in IIS, so the server was injecting it inside the script on render. Therefore breaking any good compliant code. We turned off the footer property on the IIS setting - bingo!

Lorenzo
A: 
dfsfsdf
A: 

I also face this prob. but in my case i was jquery version prob is there. I put latest version and it working greate in IE.

ramesh