:: Forum >>

Creating a template

I'm trying to create a template to show a HTMl.IMG based on a field from an XML dataset. my alert seems to be displaying the wrong field value. is there something wrong. I need to change the [obj.setAttribute("SRC", something_here] to be the value of the cell (from xml data)

My.Templates.Download.create = function()
{
    var obj = this.prototype;

    obj.setAttribute("SRC",this.getItemProperty("value") );
    obj.setStyle('width', 75);
    obj.setStyle('height','20');
    obj.setEvent("onclick",function (src){
        alert ( this.getItemProperty("value") );
    });

};
David D
Wednesday, June 22, 2005
ok, so i fixed 1 bug, but now when i use the code below, there is problem with the IF statement, any suggestions on how to get the value?

if (this.getItemProperty("value")==0) {
        obj.setAttribute("SRC","./images/d1.jpg");
        obj.setAttribute("SRC",this.value );
        obj.setEvent("onmouseover", "this.src='./images/d2.jpg'");
        obj.setEvent("onmouseout", "this.src='./images/d1.jpg'");
    }
    else {
        obj.setAttribute("SRC","./images/d2.jpg");
        obj.setAttribute("SRC",this.value );
        obj.setEvent("onmouseover", "this.src='./images/d1.jpg'");
        obj.setEvent("onmouseout", "this.src='./images/d2.jpg'");

    }
David D
Wednesday, June 22, 2005
This post maybe helps
http://www.activewidgets.com/javascript.forum.1621.0/editable-templates-with-xml-data.html
Carlos
Wednesday, June 22, 2005
Thanks, I got the initial load to load different images.
obj.setAttribute("SRC", function(){
        if (this.getItemProperty("text")=="1")
            return "./images/d1.jpg";
        else
            return "./images/d2.jpg";

    });



But Now I cant seem to get it to change on mouseover
obj.setEvent("onmouseover", function() {return "this.src='./images/d2.jpg'"});

if i use the code below it works but i can have it change to different images based on a value.
obj.setEvent("onmouseover", "this.src='./images/d2.jpg'");
David D
Wednesday, June 22, 2005
ok, so i got alittle more working, The mouseover works, but not mouseout.. any ideas

My.Templates.Download = Active.HTML.IMG

My.Templates.Download.create = function()
{
    var obj = this.prototype;


    obj.setAttribute("SRC", function(){
        if (this.getItemProperty("text")=="1")
            return "./images/d1.jpg";
        else
            return "./images/d1.jpg";

    });

    obj.setStyle('width', 75);
    obj.setStyle('height',20);

function mouseOver(){
        this.setAttribute("SRC", "./images/d2.jpg");
        this.refresh();
    }

function mouseOut(){
        this.setAttribute("SRC", "./images/d1.jpg");
        this.refresh();
    }


    obj.setEvent("onmouseout", mouseOut);
    obj.setEvent("onmouseover", mouseOver);
    

};

My.Templates.Download.create();
David D
Thursday, June 23, 2005

This topic is archived.


Back to support forum

Forum search