Dean
Dean

Reputation: 372

Passing variable in jQuery Dialog open method?

I am looking to have a jQuery dialog box which opens contents from another webpage via AJAX. I have used the .data method to pull the variable through like follows:

$(function () {
    $('#viewNote').click(function () {
        $('#dialogNotes').dialog('open');
        $('#dialogNotes').data('noteID', '37');

    return false;
});
});

$(function () {
    $('#dialogNotes').dialog({
        modal: true,
        autoOpen: false,
        open: function () {
            var noteID = $('#dialogNotes').data('noteID');
            console.log(noteID);
            $(this).load('includes/note.asp?noteID=' & noteID);
        },
        height: 300,
        width: 400,
        title: 'Notes'
    });
});

I am using console.log to verify that the noteID variable has the number 37 in it, and it writes it out into the console fine. I am then trying to add this as a parameter to the end of the URL in the $(this.load) section.

However what I am finding is, instead of the variable being used it just outputs noteID out as text, like in the below screenshot taken from Chrome when I open the page?

Variable output as text

How would I get javascript to output the value of noteID in the .load on the dialog open?

Upvotes: 0

Views: 75

Answers (1)

Christian Phillips
Christian Phillips

Reputation: 18769

You can use a + here, or maybe or string.concat() if you had multiple values.

Upvotes: 3

Related Questions