views:

24

answers:

1

Hey all,

I'm having a problem with jQuery that I thought would be simple, but I still haven't found a solution.

I have an upload form for users to upload images in WordPress, and when a user clicks "insert into post" the url of the uploaded image is supposed to go into a text input field.

I can get 1 to work fine, but when I have multiple upload buttons with multiple input fields the image url is send to the last text input only.

Here's my code:

<script type="text/javascript">
   //MEDIA UPLOADER
   jQuery(document).ready(function() {
      //Opens the upload dialog box when the button is clicked
      jQuery('#wpsa_slide_<?php echo $slidenumber; ?>_button').click(function() {
      formfield = jQuery('#wpsa_slide_<?php echo $slidenumber; ?>').attr('name');
      tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');
      return false;
  });
  //Sends the uploaded/selected file URL to the text input field
  window.send_to_editor = function(html) {
     imgurl = jQuery('img',html).attr('src');
     jQuery('#wpsa_slide_<?php echo $slidenumber; ?>').val(imgurl);
     tb_remove();
  }
});
</script>
+1  A: 
imgurl = jQuery('img',html).attr('src');

This selects all the images in your html and gets the src attribute of the first one in this collection. Probably the problem is there...

mamoo
thanks...is there a way to assign an id or class to make it unique or is there a better way to handle that?
Nathan
actually I am getting the correct image url, but for instance if I have 3 input fields, and I want the image url to go the 2nd input field, the new url is instead passed to the 3rd one...hope that makes sense :)
Nathan
Could you post a snippet of your html?
mamoo