Link to home
Start Free TrialLog in
Avatar of Panos
PanosFlag for Germany

asked on

Jquery function within function problem

Hello experts.
I'm trying to use a function inside a function but i get an undifined error.
I use one onclick function to open a popup and load a page inside the popup.
This page has "x" forms .
I add a submit button (to each form) with an onclick function:onclick="sendmessage(#currentrow#);return false;" . I was expecting to submit the form but i get "sendmessage is not defined"
All the scripting code (jquery and validation script)  is in the parent div.
May be i could load in the popup window all the scripts again and put a separate -var sendmessage = function (x) - function but i need your solution-advice.
Any help?
var showdialog = function (id) {
        $("#popuploader").dialog({
            autoOpen: false,
            bgiframe: true,
            title: "Test",
            modal: true,
            width: 450,
            height: dh,
            buttons: {
                Cancel: function () {
                    $(this).dialog("close");
                    $(this).dialog("destroy");
                },

            }
        });
        var sendmessage = function (x) {
                var d = "#myform_" + x;
                var f = d.valid();
                $(d, $(this)).validate({
                    rules: {
                        message: {
                            required: true
                        }
                    },
                    messages: {
                        message: {
                            required: requiredfield
                        }
                    }
                })

                if (f) {
                    var e = $("input#message_" + x).val();
                    var c = d.serialize();
                    $.post("customer_items/includes/sendmessage-action.cfm", c, function (g) {
                        if (g) { /*$(".mailloader").hide();*/
                            if (g == "sended") {} else {}
                        }
                    })
                }
            }
        var a = $("#popuploader");
        a.dialog("open");
        a.load("customer_items/includes/showitems.cfm?Art_ID=" + id, function (c, e, d) {
            if (e == "success") {

            } else {
                alert(errorload)
            }
        });
        return false
    };

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Proculopsis
Proculopsis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Panos

ASKER

Hi Proculopsis
The method is now accessible but i get a js error:
$(d, $(this)).validate is not a function
Can you please take a look at the this.sendmessage = function (x) ?
this.sendmessage = function (x) {
			        var tempd = "#offerform_" + x;
					var d = $("tempd");alert(d);

			        $(d, $(this)).validate({
                    rules: {
                        message: {required: true}
                    },
                    messages: {
                        message: {required:requiredfield}
                    }
                   })
			        var f = d.valid();
                    if (f) {
                        var e = $("input#message_" + x).val();
                        var c = d.serialize();
                        $.post("customer_items/includes/sendemail-action.cfm", c, function (g) {
                            if (g) {
                       
                                if (g == "sended") {
                                 } 
								else {
									}
                            }
                        })
                    }
                }

Open in new window

Avatar of Alex
Maybe you want to use the validate.js in order to validate some input fields, apparently you forgot to include the js into your file.
Avatar of Panos

ASKER

Thank you very much for your help.
i solved the second js error
regards panos
Avatar of Panos

ASKER

alex_code i missed your post.
Here is the working code:
this.sendmessage = function (x) {
                         var tempd = "#offerform_" + x;
                           var d = $(tempd);
                           
                   $(tempd).validate({
                    rules: {
                        message: {required: true}
                    },
                    messages: {
                        message: {required:requiredfield}
                    }
                   })
                         var f = d.valid();
                    if (f) {
                        var c = d.serialize();
                        $.post("customer_items/action/sendemail-action.cfm", c, function (g) {
                            if (g) {
                       
                                if (g == "sended") {
                                 }
                                                else {
                                                      }
                            }
                        })
                    }
                }