Passing Variables with jQuery

I am relatively new to jquery and javascript and I am trying to pass a unique id (number) into a flickr search function (jquery.flickr-1.0-js), for example (number is the variable where I store the unique id)

<script type="text/javascript" src="javascripts/jquery.flickr-1.0.js"></script>

 <script type="text/javascript"> 

 jQuery(function(){   
        jQuery(".btnRefresh").click(function(){
          var number = $(this).attr("id");
          $('#gallery_flickr_'+number+'').show();
            jQuery('#gallery_flickr_'+number+'').html("").flickr({      
                api_key: "XXXXXXXXXXXXXXXXXXXXXXX",     
                per_page: 15   
            });
        }); 
    }); 

  </script>

      

When I try to pass it to flickr-1.0.js function like this (shorthand)

(function ($) {
$ .fn.flickr = function (o) {

var s = {
    text: $ ('input # flickr_search _' + number + ''). val (),
   };
  };
}) (jQuery);

i get an error

number not defined [Break on this error] text: $ ('input # flickr_search _' + numbe ...] for type == 'search' free text search

please help, what do I need to do to pass a variable between two scripts?

Thank,

0


source to share


3 answers


Try setting up your scripts as shown below:

 ...
            jQuery('#gallery_flickr_'+number+'').html("").flickr({      
                    api_key: "XXXXXXXXXXXXXXXXXXXXXXX",     
                    per_page: 15,
                    search_text: $('input#flickr_search_'+number+'').val()  
            });
...



(function($) {
$.fn.flickr = function(o){

var s = {
    text: o.search_text
   };
  };
})(jQuery);

      



The idea is that you need to find the search text based on the id of the clicked item. You do this in a function where an identifier is available, then pass the input value to the flickr function with different values ​​in the hash argument. In the flickr function, you extract the named item from the hash and use the value.

+2


source


You can easily pass parameters to JQuery; eg:



$.ajax({
    type: "POST",
    url: "/<%=domainMap%>/registration/recieptList.jsp",  
    data: "patientId=" + patientId+"golbalSearch="+golbalSearch,
    success: function(response){
      // we have the response
      $('#loadPatientReciept').html(response);
    },
    error: function(e){
      alert('Error: ' + e);
    }
  });
}

      

+2


source


I just figured out "flicker"! = 'Flickr'

darn you cutesy web 2.0 names !!!

Thank!

0


source







All Articles