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 796681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:40:40+00:00 2026-05-14T22:40:40+00:00

How do I send a variable in jquery to a callback function? function(r){ }

  • 0

How do I send a variable in jquery to a callback function? function(r){ }

Look at the demo

Whilst on the demo, notice that the form above the menu can be serialised. Also notice that when clicking a folder icon whilst on an item (click a category from the left), and submit the form that way, it cannot be serialised.

I have a variable which I need to be passed to the callback function, if that’s what it’s called; to the function(r) { } section of the code.

Below is the code that works that’s above the header.

<?php $moveablecats = mysql_query("SELECT * FROM categories WHERE id != '1'  "); ?><form id="changecategoryForm2"><select id="newflex" name="thecatidichose"> <option value=""></option> <?php while($catrow =mysql_fetch_array($moveablecats)){ ?> <option value="<?php echo "$catrow[id]"; ?>"><?php echo "$catrow[title]"; ?> </option><?php } ?></select>  </form>   <p><tt id="results"></tt></p>


<script>
    function showValues() {
      var str = $("form#changecategoryForm2").serialize();
      $("#results").text(str);
    }
    $(":checkbox, :radio").click(showValues);
    $("select").change(showValues);
    showValues();
</script>

Below is the code that does not work. I am using the [jquery alerts dialogs plugin][2].
Ignore the lines that are commented out.
When the script alerts the serialised form, it is blank, so it does not work. It does however manage to show the itemid and categoryid variable.

$(".changecategory").click( function() {
   <?php $moveablecats = mysql_query("SELECT * FROM categories WHERE id != '1'  "); ?>
 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;

   jAlert(
      'Which category do you want to move <b>'+itemtitle+ '</b> to?<br><?php $moveablecats = mysql_query("SELECT * FROM categories WHERE id != '1'  "); ?><form id="changecategoryForm"><select id="newflex" name="thecatidichose"> <option value=""></option> <?php while($catrow =mysql_fetch_array($moveablecats)){ ?> <option value="<?php echo "$catrow[id]"; ?>"><?php echo "$catrow[title]"; ?> </option><?php } ?></select>  </form>   <p><tt id="results"></tt></p>','Change category', function(r) {
         // $(parenttag).fadeOut('slow');  
         $("#"+removediv).fadeOut('slow');  

         //var newflex = $("#newflex").val();
   //alert(newflex);

   alert($("#changecategoryForm").serialize());
   //alert('categoryid ' + categoryid + ' itemid ' + itemid + '.');

   //var dataString = $("#changecategoryForm").serialize();
   /*
   //remember to add validation for blank fields

   $("#loading4").show();
   $("#loading4").fadeIn(400).html('<img src="loading.gif">');

   var newrow = "134";
   $.ajax({
    type: "POST",
    url: "formcontrols.php",
    data: dataString,
    cache: false,
    success: function(html){
     $("#creation4").after(html);
     $("#loading4").hide();
     //$("#newrow").before($('itembeforehere'));
    }
   });
   */
   //
   return false;


         jAlert(''+ itemtitle +' has been successfully moved.', 'Success');
      }
   ); 


});
  • 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-14T22:40:40+00:00Added an answer on May 14, 2026 at 10:40 pm

    I think you’re probably looking for a closure, but it’s really hard to tell from your question. Here’s a simple example of a closure:

    function showLater(msg, delay) {
        setTimeout(function() {
            alert(msg);
        }, delay);
    }
    

    Think of the function we’re passing to setTimeout as the callback. When you call showLater:

    showLater("Hi there", 2000);
    

    …it returns right away, but the anonymous closure still has access to the arguments you gave to showLater, so that when it gets run a couple of seconds later, it can do the “Hi there” alert.

    One uses closures a lot when dealing with ajax calls and the like, since by default (and by preference) they’re asynchronous. (I simulated that asynchronicity above using setTimeout, to keep things simple.)

    More on closures here.

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

Sidebar

Related Questions

How do I send a javascript variable to a subsequent jquery function? Here is
Can we send variable to an input field that is in an iFrame ?
I am trying to send a variable with jQuery's getJSON function but it doesn't
I'm trying to send an ActionSheet a variable from a button. I can't use
I'm trying to send information from a form and a hidden email variable (from
Using the jQuery $.post function, if you send a null value, it arrives at
I have this jquery function function example(file, targetwidget, callback){ $(targetwidget).load(file, {limit: 25}, function(){ $(#widget_accordion).accordion({fillSpace:
I'm using Jquery, Ajax and PHP to try and send a variable to be
I want to send a string data with jquery load function but its not
I am using keyup() function to send the variable to a php page (consult.php)

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.