1

Before I get started, I know this type of question has come up before and they always get downvoted as being too narrowly focused, but I have to imagine there is a common cause here, which is why I'm bringing up my specific example. There are two errors I am encountering and they gotta be related somehow...

Overview

I have a grid of items which I populate when the page loads with various data-* attributes. All items populate the same way, yet some produce and error and some don't. I've compared all code between working and non, and it's all the same... which is to be expected because it's populated through a loop, and all data are mandatory.

Uncaught SyntaxError: missing ) after argument list

I'm receiving the "Uncaught SyntaxError: missing ) after argument list" on line 214, which is the following:

<a class='item-edit' onclick='populateModal(47F1914)' >Edit</a>

Clearly, there isn't any missing ).

Now let's look at the populateModal code:

function populateModal(id){
    var item = document.getElementById(id);
    var name = item.dataset.itemname;
    var price = item.dataset.price;
    var url = item.dataset.url; 

    document.editemform.itemname.value = name;
    document.editemform.price.value = price;
    document.editemform.url.value = url;
    document.editemform.itemid.value = id;

    $('#edititem').modal('show');  
}

As you can see, I'm not missing any parenthesis there, or any out of place curly braces, or anything. It seems pretty straight forward, and yet, I get the error in my console and the modal doesn't show on these items.

Uncaught TypeError: Cannot read property 'dataset' of null

In addition to the above error, I'm also receiving the "Uncaught TypeError: Cannot read property 'dataset' of null" error on the populateModal function.

The line it refers to is this one:

var name = item.dataset.itemname;

And as you can see from the div here, the data for itemname is in fact populated:

<div class='item-image' id='E7A1938' data-itemname='A book about things' ...>

I'm stumped. Any thoughts?

bryanx
  • 159
  • 1
  • 3
  • 11
  • 1
    `47F1914` isn't valid. You need to wrap that in quotes: `"47F1914"`. – Mike Cluck Feb 18 '16 at 23:44
  • This is a duplicate, but the simple answer is that the argument isn't wrapped in quotes, it needs to be `populateModal("E7A1938")` etc – adeneo Feb 18 '16 at 23:45
  • @adeneo Wait a minute. This isn't a duplicate of that question at all. That question was about finding elements using different selectors, not an invalid string. – Mike Cluck Feb 18 '16 at 23:47
  • Thank you @adeno, I feel so dumb! That was it! – bryanx Feb 19 '16 at 00:24

0 Answers0