Mangs
Mangs

Reputation: 1140

Pass parameter to jQuery dialog

I want to pass a string into my dialog like this:

    ('#buttonSaveRight').click(function () {
      if (!ErrorHandlingSaveDialog()) {
      return false;
      }
      var nr = "testdata1";

      $("#dialogSaveConfirmation").data('param', nr).dialog('open');
      return false;
    });

and recieve it like this:

$('#dialogSaveConfirmation').dialog(

    {
        autoOpen: false,
        modal: true,
        width: "auto",
        buttons: {
            "Save": function () {
                var nr= $('#dialogSaveConfirmation').data('param');

                alert(nr); //this is just for testing if I recieved the data or not
                //etc

What am I doing wrong? Is there some other way that I can pass data into my dialog?

Best regards Johan

Upvotes: 3

Views: 8550

Answers (1)

Aditya Singh
Aditya Singh

Reputation: 9612

Try this out:- http://jsfiddle.net/adiioo7/StMyA/

The above code is working fine on my end.

JS:-

$('#dialogSaveConfirmation').dialog({
    autoOpen: false,
    modal: true,
    width: "auto",
    buttons: {
        "Save": function () {
            var nr = $('#dialogSaveConfirmation').data('param');

            alert(nr);

        }
    }});

$("#dialogSaveConfirmation").data('param', "asdsa").dialog('open');

Upvotes: 6

Related Questions