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

LVL 2
PanosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ProculopsisCommented:


var sendmessage = function (x)...

// makes it a protected method

this.sendmessage = function (x)...

// will make the method publicly accessible
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PanosAuthor Commented:
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

0
AlexSoftware EngineerCommented:
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.
0
PanosAuthor Commented:
Thank you very much for your help.
i solved the second js error
regards panos
0
PanosAuthor Commented:
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 {
                                                      }
                            }
                        })
                    }
                }
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.