views:

672

answers:

4

i dont have a clue how i should rewrite this jquery so i can pass parameters into it. i want to pass an id into the function so i place it like, $(".dialog" + id).

i am goin to trigger it with a <a>

$(document).ready(function() {                 
  $(".btnCheck").live("click", function(evt) {
    evt.preventDefault();                               
    $(".dialog").dialog({
      height: 700,
      width: 600,
      closeOnEscape: true,
      title: 'prev'
    }).dialog("open");
  });           
});
A: 

You need to associate your buttons with you dialogs somehow.

If you give the buttons a class of button and the dialogs a class dialog. You can then get all this into an array and loop through them the first button in the array will activate the dialog which has an id of dialog1.

matpol
+1  A: 

assuming that what you want is the ID of "btnCheck.

$(document).ready(function() {                 
        $(".btnCheck").live("click", function(evt) {
            evt.preventDefault();                               

            $(".dialog" + $(this).attr("id")).dialog({ height: 700, width: 600, closeOnEscape: true, title: 'prev' }).dialog("open");
        });           
    });
andres descalzo
+1  A: 

Assuming:

<input type="button" class="btnCheck" id="btn1" value="Click Me">
...
<div id="dialog-btn1" class="dialog">
  ...
</div>

you can do:

$(function() {
  $(":button.btnCheck").live("click", function(e) {
    $("#dialog-" + this.id).dialog({...});
    e.preventDefault();
  });
});

You'll note that instead of using a dynamic class name, I gave the div a class of dialog. To get a specific one, since you will only ever want one (at a time), an ID is a better choice (imho).

this within this event handler refers to the button that was clicked ie the source of the event.

cletus
A: 

how could i do this if i want to use a ahref?

Dejan.S