views:

96

answers:

2

I have this HTML/PHP

<input name="add to list" class='fncAdd' id='moodal_close' value="add to list" onclick="cajaxUpdateCartProduct('<?= $value->id ?>', 'quantity_<?= $value->id ?>', '<?= $this->sitePfx ?>/cart/');" type="button">

In my javascript I have

$('moodal_close').addEvent('click', function(){
        alert("1");
    });

In my firebug console the only response I get is

$("moodal_close") is null

+4  A: 

Are you trying to add the event before the element is created? You might try:

window.addEvent('domready', function() {
    $('moodal_close').addEvent('click', function(){
        console.log('sup');
    });
});
Zack
the content is in a modal window so is not present on domready, I assume this is the problem, how would i get around this?
sea_1987
You've got addEvent in one window, and the actual element in another? That'll never work. Javascript in one window can't (for most practical purposes) really talk to javascript in another window. You'd have to have the addEvent in the same window as the element.
Marc B
Cheers - this one stumped me for 3 days.
Julian H. Lam
A: 

Your input tag should have a name of "moodal_close" instead of "add to list"

infinitone