views:

26

answers:

1

Code:

DeCheBX = $('MyDiv').insert(new Element('input', { 'type': 'checkbox', 'id': "Img" + obj[i].Nam, 'value': obj[i].IM, 'onClick': SayHi(id)           }));
                            document.body.appendChild(DeCheBX);
                            DeImg = $('MyDiv').insert(new Element('img', { 'id': "Imgx" + obj[i].Nam, 'src': obj[i].IM }));
                            document.body.appendChild(DeImg);
                        }
                        SayHi = function(x) {
                            try {

                            if($('x').checked == true)
                            {
                                alert("press" + x);
                            }

                    }
                    catch (e) {
                        alert("error");
                    }

                };
A: 

1: You should declare your variables DeCheBX, DeImg and SayHi with the var keyword.
2: In the example it is unclear where obj[i] comes from and what it is. Errors may stem from it being not what you hope.
3: You most certanly don't want to call the function SayHi and assign its return value (undefined) to the onclick handler of the Element you construct and insert into 'MyDiv'. The way you are doing things, It'd better be a string like "SayHi(this);".
4: There is an extra } after document.body.appendChild(DeImg);. It makes this part of your example code invalid.
5: In the function SayHi you look at the checked property of an element with id 'x'. It seems to me that you'd rather want to use the value of the x passed to the function (see 3 above).

npup
i wanted to call like when i click on checkbox it should call the function related to it
vicky
obj is json string which i m calling in it.the x would be value of checkbox id on which i have clicked.DecheckBx.
vicky