views:

155

answers:

2

Since I will be storing the employees who are out on vacation and back at work in a database table, I need to call deleteImage($item,$unid) function on page load. Not sure how to.

This is the function that is called when the suitcase icon is clicked (suitcase=out on vacation)

 $('ul.gallery > li').click(function(ev) {
var $item = $(this);
var $unid = $(this).attr('id');
var $target = $(ev.target);
if ($target.is('a.ui-icon-suitcase')) {
    deleteImage($item,$unid);
} else if ($target.is('a.ui-icon-arrowreturnthick-1-w')) {
    recycleImage($item,$unid);
}
return false;
 });

$item = $(this), and unid is the employeeID. How can I pass $(this) without a clicky event?

There is also a droppable function :

   $suitcase.droppable({
            accept: '#gallery > li',
            activeClass: 'ui-state-highlight',
            drop: function(ev, ui) {
                var $unid = $(ui.draggable).attr('id');
                deleteImage(ui.draggable,$unid);
            }
        });

I am not sure if it will be even possible to call this function on page load. any help?

+1  A: 

When you call the deleteImage($item, $unid) function, which image element are you trying to delete? This is important as that will take the place of the $(this).

Say you want to remove the first <li> tag in the gallery, then you can trigger a click on that item as follows:

 $(document).ready(function(){
  $('ul.gallery > li:first').trigger('click');
 })

Wrapping that trigger function inside of a document.ready function will call the function on page load (after the DOM is fully loaded)

And one more note, there is no need to wrap the ui.draggable object because it is already a jQuery object... this will work : ui.draggable.attr('id');

fudgey
hi fudgey, i appreciate your reply. the $('ul.gallery > li:first').trigger('click');won't work. Also, is it possible to replace li:first with li id?
FALCONSEYE
If you know the ID then just use `deleteImage( $('#someID'), id);` inside the document.ready
fudgey
A: 

i have this:

        $('#clicky').click(function() {
            $('#1678').trigger('click');
            alert(1);
        });


        $('#gallery > li:first').click(function() {
            var myID = $(this).attr('id');
            alert('myID is :'+myID);
        });

1678 is the id for li:first. So, if I click on my 'clicky' button, it will alert 'myID is: 1678' correctly. So, I need to somewhat trigger the deleteImage function from here.

FALCONSEYE
oh, found another thing. i modified the very first function to:$('ul.gallery > li').click(function(ev) { var $item = $(this); var $unid = $(this).attr('id'); var $target = $(ev.target); if ($target.is('a.ui-icon-suitcase')) { deleteImage($item,$unid); } else if ($target.is('a.ui-icon-arrowreturnthick-1-w')) { recycleImage($item,$unid); } else { alert('say whhaaat?'); } return false; });i get 'say whaat?' alert. so, i am almost there. if i put } else { deleteImage($item,myID); } last section, it will work.
FALCONSEYE
it works :) all i had to do is to loop thru my query after the drag/drop functions : <cfoutput query="qryExcEmployees"> $('###unid#').trigger('click'); </cfoutput>
FALCONSEYE
OH I see you got it - Great! Just for future reference, it would be best if you added updates to the end of your original question as it keeps everything together and you can actually post formatted code ;)
fudgey