views:

30

answers:

1

I am using the eBay JavaScript Finding API. The currency id member of the findItemsAdvancedResponse object is defined as @currencyId. So I am retrieving this value as:

function _cb_findItemsAdvanced(root) {
    var items = root.findItemsAdvancedResponse[0].searchResult[0].item || [];
    var html = [];
    if (items.length == 0) {
        html.push('No Results');
    }
    for (var i = 0; i < items.length; ++i) {
        var item     = items[i];
        var title    = item.title;
        var pic      = item.galleryURL;
        var viewitem = item.viewItemURL;
        var price = Number(item.sellingStatus[0].currentPrice[0].`__value__`).toFixed(2);
        var currency = ""
        var currency = item.sellingStatus[0].currentPrice[0].@currencyId;
        if (null != title && null != viewitem) {
            html.push('<div class="item-layout5"><table><tr><td><div style="width:102px;overflow:hidden;">');
            html.push('<a href="' + viewitem + '" target="_blank" rel="nofollow"><img src="' + pic + '" border= "" alt="' + title + '" /></a></div></td>');
            html.push('<td><span class="itemname"><a href="' + viewitem + '">' + title + '</a></span></td></tr>');
            html.push('<tr><td><img src="PTMFOG0000000064.gif" alt="" /></td><td><span class="buyprice">' + currency + ' &#36;' + price + '</span></td></tr></table></div>');
        }
    }
    document.getElementById("results").innerHTML = html.join("");

}  // End _cb_findItemsByKeywords() function

This works fine for Firefox browsers, but not for Google Chrome or IE (I get a compilation error).

Is using the @ symbol in a member name acceptable in JavaScript? And what workaround can I use so that the above code will work in all browsers?

thanks...

+3  A: 

In javascript, the syntax

  foo.bar

is equivalent to

  foo['bar']

and the latter works even when 'bar' is not a valid identifier name, as in this case.

LarsH
Cool - thanks from a JavaScript noob! Just to complete things, the following line of code works in IE, Firefox and Chrome: var currency = item.sellingStatus[0].currentPrice[0]['@currencyId'];
igotmumps
@igotmumps No problem. :-)
LarsH