Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2008
    Location
    Fareham
    Posts
    87
    Tokens
    2,716

    Latest Awards:

    Default [JS] Changing this function?

    Hey everyone, well I am sorta stuck on changing this function, can anyone help me?

    Well, here is this function I am talking about...

    Code:
    function add(obj)
    {
        var add = confirm("Do you wish to add \"" + obj.title + "\" to the your home?");
        
        var grid = document.getElementById("grid");
        
        var imgDump = document.getElementById("imgDump");
        
        if (add)
        {
            var newId = "drag_" + getRandomId();
            
            imgDump.innerHTML = '<img src="' + obj.src + '" id="' + newId + '"/>';
            
            var newObj = document.getElementById(newId);
            
            alert("\"" + obj.title + "\" has been successfully added to your home!");
        
            grid.innerHTML += 
            '<div title="' + obj.title + '" id="' + newId + '" onmousedown="dragStart(this.id);" onclick="getObjectInfo(this.id);"' +
            'style="width:' + newObj.clientWidth + 'px; height:' + newObj.clientHeight + 'px; background-image:url(' + obj.src + '); top:0px; left:0px; z-index:1;"' +
            'class="drag_object"></div>';
            
            imgDump.innerHTML = "";
        }
    }


    How would I make it so instead of the code being onclick="add(this)" it does something like onclick="add('bling_stars');"?

    Bling stars being the image title and or name.

    Thanks for any help given guys!
    Forever on the dance floor.

  2. #2
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    If you want it to find the element with the ID "bling_stars", just do:

    Code:
    function add(obj)
    {
    
        var obj = document.getElementById(obj);    
    
        var add = confirm("Do you wish to add \"" + obj.title + "\" to the your home?");
        
        var grid = document.getElementById("grid");
        
        var imgDump = document.getElementById("imgDump");
        
        if (add)
        {
            var newId = "drag_" + getRandomId();
            
            imgDump.innerHTML = '<img src="' + obj.src + '" id="' + newId + '"/>';
            
            var newObj = document.getElementById(newId);
            
            alert("\"" + obj.title + "\" has been successfully added to your home!");
        
            grid.innerHTML += 
            '<div title="' + obj.title + '" id="' + newId + '" onmousedown="dragStart(this.id);" onclick="getObjectInfo(this.id);"' +
            'style="width:' + newObj.clientWidth + 'px; height:' + newObj.clientHeight + 'px; background-image:url(' + obj.src + '); top:0px; left:0px; z-index:1;"' +
            'class="drag_object"></div>';
            
            imgDump.innerHTML = "";
        }
    }
    If you don't mean that, please expand your post, thanks.

  3. #3
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    Lol basically onclick="add('bling_stars');" and I think bling_stars will have to be the ID seeing as you'd be grabbing it using the ID " var obj = document.getElementById(obj);"
    Hi, names James. I am a web developer.

  4. #4
    Join Date
    Apr 2008
    Location
    Fareham
    Posts
    87
    Tokens
    2,716

    Latest Awards:

    Default

    Never mind, edited it and Simons code worked, cheers mate!
    Last edited by Remotive; 19-04-2008 at 09:54 PM.
    Forever on the dance floor.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •