0

I have a table row that when clicked opens a dialog. The class of the table row is either "associated" or "unassociated". I am trying to create the buttons for the dialog, but they will be different based on the class of clicked row.

  $('#opps tr').click(function(){
         var thisClass = $(this).attr('class');
         $('#oppData').dialog({
                            width: dWidth,
                            height:dHeight,
                            modal:true,
                            buttons: {
         //if thisClass == unassociated
                     "Submit":function(){ //do stuff }

         // if thisClass == associated
                     "Do Other stuff":function(){}
                           }
    });
 });

how can i achieve this?

1 Answer 1

1

You can do this with a little code refactoring. At the heart of the answer is the jQuery function hasClass which will help you determine your buttons properties. I'm also using the idea that every JSON object is just a property bag and building out myButtons using the property bag syntax.

$('#opps tr').click(function(){
         var myButtons= {};

         if ($(this).hasClass("associated")) {
            myButtons["Submit"] = function () { ... };
         } else {
            myButtons["Do Other stuff"] = function(){ ... };
         }

         $('#oppData').dialog({
                            width: dWidth,
                            height:dHeight,
                            modal:true,
                            buttons: myButtons
         });
 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.