Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 533095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:28:24+00:00 2026-05-13T09:28:24+00:00

I have a onclick event that has a value in it that I want

  • 0

I have a onclick event that has a value in it that I want to post to a backend php script. Just not sure how to get it in the dialog function.

function reorder(job_index)//<--------this fella
{
        $('#dialog').dialog('open');
}
$(document).ready(function(){
    $(function() {
        $("#dialog").dialog({
        bgiframe: true,
        autoOpen: false,
        height: 250,
        width: 600,
        modal: true,
        buttons: {
            'Yes, use the number above': function() {
            var jobID=$("#jobnumber").val();
            $.post("rpc.php",   {           
                                job_index:job_index,// <-------to here          
                                jobID:jobID,
                                method: "reorder"
                                },
    function(data,textstatus)
        {
        alert(data.message);    
        }, "json");
            },
            'No, create a new number for me': function() {
                $(this).dialog('close');
        },
            Cancel: function() {
                $(this).dialog('close');
            }

        }
    });
});
});

The value is job_index. Any tips?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:28:25+00:00Added an answer on May 13, 2026 at 9:28 am

    In the below code, I’m using a single function that will allow you to both store and retrieve your index.

    The function index is creating a closure by returning declaring and returning another function. This means that the variable _index will still be available (think of it as like the variable was allocated on the heap instead of the stack-frame; ie malloc-ed) once the (outer) function has returned, and as you can see the function is self-invoking, due to the }(); on the last line of the function, thus returning immediately during parsing.

    Then when you call the function index again (which now you will be basically calling the inner function that takes one formal argument, ind), you can pass in your index and if you do, the function will store it in the _index variable that I mentioned earlier on…ie the variable that is still available after the outer function returned.

    If you don’t pass in an argument (ie invoke the function like such: index()), the function only returns your stored variable. The logic behind this is that if a parameter is not passed, the value of the actual argument is undefined. Thus the function checks if the value is undefined, and if it is, it justs returns your variable.

    And btw, you have a nested ready function inside your outer ready function. This is because $(function() { is the same as $(document).ready(function(){. I fixed this in the below code:

    var index = function () {
        var _index;
        return function (ind) {
            if (typeof ind !== "undefined") {
                _index = ind;
            }
            return _index;
        };
    }();
    
    function reorder(job_index)
    {
        index(job_index);
        $('#dialog').dialog('open');
    }
    
    $(function () {
        $("#dialog").dialog({
            bgiframe: true,
            autoOpen: false,
            height: 250,
            width: 600,
            modal: true,
            buttons: {
                'Yes, use the number above': function () {
                    var jobID = $("#jobnumber").val();
                    $.post("rpc.php", {
                        job_index: index(),                 
                        jobID: jobID,
                        method: "reorder"
                    },
    
                    function (data, textstatus) {
                        alert(data.message);
                    },
                    "json");
                },
                'No, create a new number for me': function () {
                    $(this).dialog('close');
                },
                Cancel: function () {
                    $(this).dialog('close');
                }
    
            }
        });
    });
    

    Another way to do it is by using the data method that nickf mentioned. This will allow you to store the index directly as part of your element, like such:

    function reorder(job_index)
    {
        $('#dialog').data("job", job_index).dialog('open');
    }
    
    $(function () {
        $("#dialog").dialog({
            bgiframe: true,
            autoOpen: false,
            height: 250,
            width: 600,
            modal: true,
            buttons: {
                'Yes, use the number above': function () {
                    var jobID = $("#jobnumber").val();
                    $.post("rpc.php", {
                        job_index: $("#dialog").data("job"),                 
                        jobID: jobID,
                        method: "reorder"
                    },
    
                    function (data, textstatus) {
                        alert(data.message);
                    },
                    "json");
                },
                'No, create a new number for me': function () {
                    $(this).dialog('close');
                },
                Cancel: function () {
                    $(this).dialog('close');
                }
    
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a gridview control that has on onclick event bound to every cell.
I have a onclick event that is like: public void OnMyButton_Click(object sender, EventArgs e)
I have an onclick event called in a PHP foreach loop for several items
I have some buttons with an onclick attribute and some that don't. I want
i want to have in my application an alertdialog, that has its message updated
I've got a button that has an onclick event in it, which was set
I have a button has action which can set myBackingBean.myString, and onclick event calls
I have a function which executes on click event, but the thing is that
I have a table in HTML, and I have an onclick event for its
On Window 's load, every DD element inside Quote_App should have an onCLick event

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.