3 Replies - 2316 Views - Last Post: 05 April 2014 - 12:05 PM

#1 SquareRoot22   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-April 14

Appending thumbnail images returning “undefined”

Posted 05 April 2014 - 09:30 AM

I need a second set of eyes on this one here is a url and the code:
http://theimpactgrou...prototype6.html

$(function() {
    thumbnails = ['images/image1.png', 'images/image2.png', 'images/image3.png', 'images/image4.png', 'images/image5.png', 'images/image6.png', 'images/image7.png', 'images/image8.png']
        $('#images img').click(function(e) {
            e.preventDefault();
            var newImage = $('<img src="' + thumbnails.filename + '"/>');
            var dragdiv = $('<div class="draggable">' + newImage.value + '</div>');
            $('#imageBox').append(dragdiv);
            $('.draggable').draggable({
                scroll: false,
                containment: '#imageBox'
            });
            $('.draggable img').resizable({
                handles: "all"
        });
});


This post has been edited by andrewsw: 05 April 2014 - 09:53 AM
Reason for edit:: Fixed code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Appending thumbnail images returning “undefined”

#2 andrewsw   User is offline

  • no more Mr Potato Head
  • member icon

Reputation: 6957
  • View blog
  • Posts: 28,696
  • Joined: 12-December 12

Re: Appending thumbnail images returning “undefined”

Posted 05 April 2014 - 10:01 AM

Your array thumbnails doesn't have a filename property, nor does newImage have a value property - so it is undefined.

You could use jQuery index() to find the number of which element was clicked, and use this value to return the filename from your array, thumbnails[x].

Probably..
var ind = $('#images img').index(this);

This post has been edited by andrewsw: 05 April 2014 - 09:59 AM

Was This Post Helpful? 0
  • +
  • -

#3 SquareRoot22   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 05-April 14

Re: Appending thumbnail images returning “undefined”

Posted 05 April 2014 - 10:03 AM

View Postandrewsw, on 05 April 2014 - 10:01 AM, said:

Your array thumbnails doesn't have a filename property, nor does newImage have a value property - so it is undefined.

You could use jQuery index() to find the number of which element was clicked, and use this value to return the filename from your array, thumbnails[x].

Probably..
var ind = $('#images img').index(this);

Was This Post Helpful? 0
  • +
  • -

#4 laytonsdad   User is offline

  • I identify as an attack helicopter!
  • member icon

Reputation: 467
  • View blog
  • Posts: 1,998
  • Joined: 30-April 10

Re: Appending thumbnail images returning “undefined”

Posted 05 April 2014 - 12:05 PM

Do you have another question?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1