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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:28:16+00:00 2026-06-07T04:28:16+00:00

I have this jQuery object which I need to pull into a function, is

  • 0

I have this jQuery object which I need to pull into a function, is this possible? Please see the code snippet:

    var input;
    jQuery('.upload').live('click', function()
    {
    input = jQuery(this).find(".image-path");
    tb_show(title, 'media-upload.php?type=image&TB_iframe=true');

    return false;
    }); 

    window.send_to_editor = function( html ) 
    {
         if (input)
         {
              console.log(input); // works and defined at this point...
              var data {
              action: "doFunction"
              };
              jQuery.post( ajaxurl, data, function( response ) 
              {
                   console.log(input); // does not work, not defined...why??
                   input.val(response); // this gives me input.val(response) is not a function
              });
         }
    }
  • 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-06-07T04:28:18+00:00Added an answer on June 7, 2026 at 4:28 am

    Major edit now that the OP has disclosed their actual code:

    The problem is that the value of input is not set until sometime later when the upload button is clicked, but you’re trying to use that value before then, thus it’s still uninitialized. You should change your code to something like this:

    jQuery('.upload').live('click', function()
    {
        var input = jQuery(this).find(".image-path");
        if (input.length) {
            var data {
                action: "doFunction"
            }
            jQuery.post( ajaxurl, data, function( response ) {
                input.val(response); // this gives me input.val(response) is not a function
            });
        }
        return false;
    }); 
    

    I’m still unsure that your jQuery matches your HTML appropriately since you haven’t disclosed your HTML. Your current code is looking for an object with class="image-path" that is a child of the clicked on button. That is a bit unusual form of HTML which makes me suspect your jQuery isn’t right for your HTML which would be another problem to fix.


    Original answer before the OP disclosed their actual code.

    All you have to do is two things:

    1. Make sure that imageObj is defined in the proper scope so it’s available in your response callback.
    2. Make sure that the jQuery object resolves to the proper type of DOM object that has a .val() method. Since it’s generally <input> objects that have a .val()method that works and <input> objects aren’t usually container objects, I suspect this is at least part of your problem.

    There are two ways to make sure that imageObj is declared in the proper scope:

    1. Declare it globally so it’s available as a global variable (not generally recommended).
    2. Declare it in a parent scope so it’s available in the callback function. Here’s an example of declaring it in a parent scope.

    Like this:

    function myFunc() {
    
        var imageObj = jQuery(this).parents('.image-wrapper');
    
        var data = {
        action: "doAjax"
        };
    
        jQuery.post(ajaxURL, data, function(response) 
        {
            imageObj.val(response); // this is undefined when run
        });  
    
    }
    

    To make sure that imageObj resolves to the proper type of DOM object, you can add debugging code to first check to see if imageObj.length is non-zero and then you need to make sure that the parent object(s) with class="image-wrapper" are actually <input> objects that have a working .val() method. Since input objects usually are not container objects, this may be part of your problem. We could advise more specifically if you showed us your HTML.

    Here’s a working example: http://jsfiddle.net/jfriend00/EJ8yu/

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

Sidebar

Related Questions

I have this jquery function that works, except I need to add something. I
I have this jQuery code: $(document).ready(function() { $.ajax({ url: pages/+page+.php, cache: false }).done(function( html
I have this jQuery script that works fine: $(select).change(function () { var finalPrice =
I have this jQuery snippet, I have stored the variables to highlight them. var
I have this jQuery code in my JSP page (jQuery 1.7.2) : function Header()
i have this jquery code $(#eioShowLink).on('click',function(){ $(#ioEditRelatedConcepts).html(''); $.getJSON(http://localhost/Mar7ba/Ontology/getRelatedConceptsAndRelations/+conceptName+/TRUE, function(data){ var concepts = data[0]; var
I have the following code: $('#main-nav a').mouseover(function() { var name = $(this).attr(rel); $(#subnav ul.
Does anyone have any idea what this jQuery selector will do? object.find('td:eq(1) div div');
I have this jQuery: $(document).ready(function() { $(#panel).hide(); $('.login').toggle( function() { $('#panel').animate({ height: 150, padding:20px
I have this jquery script which suppose to hide/show div element base on the

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.