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

  • Home
  • SEARCH
  • 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 775589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:18:51+00:00 2026-05-14T19:18:51+00:00

How do I send a javascript variable to a subsequent jquery function? Here is

  • 0

How do I send a javascript variable to a subsequent jquery function?
Here is my code.

    <script type="text/javascript">
$(function() {
    var name = $("#name"),
        email = $("#email"),
        password = $("#password"),
        itemid = $("#itemid"),
        tips = $(".validateTips");

    function updateTips(t) {
        tips
            .text(t)
            .addClass('ui-state-highlight');
        setTimeout(function() {
            tips.removeClass('ui-state-highlight', 1500);
        }, 500);
    }

    $("#dialog-form").dialog({

        autoOpen: false,
        height: 320,
        width: 350,
        modal: true,
    /*
        buttons: {
            'Change category': function() {
            alert("The itemid2 is "+itemid2);

                var bValid = true;
                $('#users tbody').append('<tr>' +
                '<td>' + name.val() + '</td>' + 
                '<td>' + email.val() + '</td>' + 
                '<td>' + password.val() + '</td>' +
                '<td>' + itemid.val() + '</td>' +
                '</tr>'); 

                $(this).dialog('close');

            },
            Cancel: function() {
                $(this).dialog('close');
            }
        },
        */
        close: function() {
            allFields.val('').removeClass('ui-state-error');
        }
     });



    $('.changecategory')
        .button()
        .click(function() {
              var categoryid = $(this).attr("categoryid");
              var itemid = $(this).attr("itemid");
              var itemid2 = $(this).attr("itemid");
              var itemtitle = $(this).attr("itemtitle");
              var parenttag = $(this).parent().get(0).tagName;
              var removediv = "itemid_" +itemid;
         alert("The itemid is "+itemid);

            $('#dialog-form').dialog('open');




        });

});
</script>

I’ll break it down.

  1. The .changecategory section happens FIRST when an image on my page is clicked.
  2. $(“#dialog-form”).dialog({ is then called, and the variable item id is not passed to this function. How can I pass a variable from one function to another? Is that possible.

Is there a way I can pass a variable to another jquery function without having to resort of setting a cookie with javascript and then using jquery to read it?

  • 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-14T19:18:52+00:00Added an answer on May 14, 2026 at 7:18 pm

    Your dialog('open') call won’t be able to see any of your itemid variables you defined because they’re in a completely different closure.

    If you’d tell us which dialog plugin you’re using we could help you out a bit. If it’s jQuery UI Dialog widget then I suggest you do this:

    $('.changecategory')
        .button()
        .click(function() {
            var scope = $(this); // for the sake of code speed
            var categoryid = scope.attr("categoryid");
            var itemid = scope.attr("itemid");
            var itemid2 = scope.attr("itemid");
            var itemtitle = scope.attr("itemtitle");
            var parenttag = scope.parent().get(0).tagName;
            var removediv = "itemid_" +itemid;
            alert("The itemid is "+itemid);
            $('#dialog-form').dialog('option', 'itemId', itemId); // store the id
            $('#dialog-form').dialog('open');
        });
    

    So before you open the dialog, you can set some dialog’s internal option that will be available in the closure of the open function as dialog’s option.

    The other (non-recommended way) would be to use @Tgr’s approach with globals.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Javascript I can send XML string to JSP server (XmlAction.jsp): Javascript Code: var
I am trying to send a variable from a Javascript to a php script
Is it possible to send a variable number of arguments to a JavaScript function,
I want to send base64 string through ajax I encoded it through JavaScript function
How can I send a JavaScript array as a JSON variable in my AJAX
I have declared branch as a variable in the head. Its a JavaScript function
I'm trying to convert this Javascript code: self.userSerialEvent = function (join, value, tokens) {
I'm attempting to put a php variable inside a javascript function and having no
How to send a javascript array to PHP using Jquery Ajax.(Note: i will get
I'm using Jquery, Ajax and PHP to try and send a variable to be

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.