This is really not a UI question, but since I didn't see the original
thread on the main list...

> [ ... ] If i do it like i do below then i get "somevar not set" because i
> think the dialog function is run before i click the button image.
>
>          $("#dialog").dialog({
>                  buttons:{
>                    "Delete": function() {window.location = "/home/" +
> somevar ;},
>                  }
>          });
>          $(".button").click(function(){
>                  var somevar = $(this).attr("id");
>                  $("#dialog").dialog("open");
>          });
>   });

That's not quite it.  The problem is that by declaring somevar with
"var" you gave it the scope of the current function, which has
completed by the time you click the delete button in dialog.  So at
that point somevar does not exist.

> Any way to solve this?

Yes, you need some place to store somevar.  One option might be to
keep in the the global scope, which should work if you just removed
"var" from the declaration.  But there are many reasons why this is
not considered great practice.  The other obvious place to store it is
in the dialog itself, with a line something like:

    $("#dialog").data("somevar", $(this).attr("id"));

Then the delete function could use something like:

    window.location = "/home/" + $(this).data("somevar") ;

This is entirely untested, but I think it should get the idea across.

Good luck,

  -- Scott

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery UI" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jquery-ui?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to