views:

44

answers:

1

function Psend() {

     new Ajax.Request('Handler.ashx',
        {
            method: 'get',
            onSuccess: function(transport) {
                var response = transport.responseText || "no response text";
                //alert("Success! \n\n" + response);
                var obj = response.evalJSON(true);

                for (i = 0; i < 4; i++) {

                    DeCheBX = $('MyDiv').insert(new Element('input', { 'type': 'checkbox', 'id': "img" + obj[i].Nam, 'value': obj[i].IM, 'onClick': 'SayHi(this,i)' }));
                    DeImg = $('MyDiv').insert(new Element('img', { 'id': "img" + obj[i].Nam, 'src': obj[i].IM, 'style': 'display = inline', 'onClick': 'Say(this)' }));
                    document.body.appendChild(DeCheBX);
                    document.body.appendChild(DeImg);

                }

            },
            onFailure: function() { alert('Something went wrong...') }
        });


        SayHi = function(x,i) {

            if ($(x).checked == true) {

                //               $('id').hide();

                **$('img'+i).style.visibility = "hidden";**// doesnt work 
            }



        };

Handler.ashx public class Handler : IHttpHandler {

public void ProcessRequest(HttpContext context)
{

    string[] Img = new string[5] { "http://farm4.static.flickr.com/3210/3033577103_f80cb2e399_t.jpg", "http://farm1.static.flickr.com/76/184936863_dceeaa048c_t.jpg", "http://farm4.static.flickr.com/3133/2630880079_9035711f2f_t.jpg", "http://farm4.static.flickr.com/3064/2395929114_a4d69a22c6_t.jpg", "http://farm3.static.flickr.com/2195/2214604053_1de19931cf_t.jpg" };
    int[] Name = new int[5] { 1, 2, 3, 4, 5 };
    StringBuilder output = new StringBuilder();
    // output.Append("\"Images\":\" ");
    output.Append("[");
    for (int i = 0; i < 5; i++)
    {
        output.Append("{");
        output.Append("\"Nam\":\"" + Name[i].ToString() + "\",");
        output.Append("\"IM\":\"" + Img[i] + "\" ");
        if (i != 4)
        {
            output.Append("},");
        }
    }

    output.Append("}]");
    context.Response.Write(output);



}

public bool IsReusable
{
    get
    {
        return false;
    }
}

} output

<input id="Button1" value="button" onclick=" Psend()" type="button">
+1  A: 
$('img'+i)

i is undefined.

Update: You are setting the element id as "img" + obj[i].Nam.

Steve-o
i am sorry i forgot to update my program.still is doesnt work
all variable defined...