0

I have this code in my javascript

        $('#process-title').html(projectData.process-title);
        $('#process-description').html(projectData.process-description);
        $('#process-wireframes').empty('');
        $.each(projectData.process-wireframes, function(item) {
            $('#process-images').append('<div class="project-gallery"><img src='+projectData.process-wireframes[item]+' /></div>')
        });

It doesn't work for some reason and is currently breaking my site http://darrenbachan.com/. I am not sure how to fix this, I have no javascript knowledge and the threads I've read make it that even more difficult to understand. How do I define these, uhhh, are they functions?

Edit: I forgot to mention you need to click on a project to see the error.

Darren Bachan
  • 735
  • 2
  • 11
  • 30

1 Answers1

3

You can't use hyphenated properties like that. The browser is interpreting that as subtractions like this:

projectData.process - title
projectData.process - description
// etc.

You need to access them using strings.

projectData['project-title']
projectData['process-description']
// etc.
Mike Cluck
  • 31,869
  • 13
  • 80
  • 91
  • $('#process-title').html(projectData.['process-title']); This gives me a syntax error. I will try one word, but I know I've tried "test" and it was still giving me problems. – Darren Bachan May 13 '16 at 22:16
  • @DarrenBachan Don't include a dot. `projectData['process-title']`, not `projectData.['project-title']`. – Mike Cluck May 13 '16 at 22:19
  • Thanks. I don't get that error anymore, but now I'm getting "Uncaught TypeError: Cannot read property 'length' of undefined" – Darren Bachan May 13 '16 at 22:26
  • @DarrenBachan That's a different problem altogether. Try debugging it yourself then if you get stuck, post a new question on Stack Overflow. – Mike Cluck May 13 '16 at 22:27
  • Oh ya? Damn, but it's weird, if I remove lines 259-264 from http://darrenbachan.com/js/main.js it works fine. I'm not good at reading or writing Javacript. What I have is written from someone I know. I'll have to post another question, I'm not sure what code I'd reference in the post. I can suspect its 259-264 that's causing it but I'm not sure. – Darren Bachan May 13 '16 at 22:31
  • Wait, okay I seem to have it working now, I just need to magically write if/else statements to say if there's content show it if not hide it. – Darren Bachan May 13 '16 at 22:35