I have set a var in my code then made it global, but for some reason, dialog is showing it as ‘undefined’. Can you not have var in title? Thanks
In .click event
box = $('#EB_custref').val();
Outside of function
var box;
In dialog options
title: 'Edit box' + ' ' + box,
The
title: 'Edit box' + ' ' + boxline gets run when you instantiate your dialog: I assume you’re doing that on$(document).ready. At that point, yourboxvariable is undefined.When you set
boxon theclickevent it’s too late – the title has already been set.See this post for further info.
EDIT
Here’s a demo of one solution for this:
HTML
JQUERY
Note the use of HTML5-style
data-attributes, which rock, and are accessible in jQuery through the.data()function. Also note that I’ve used a global variable to show you that it’s possible to use one. However there’s no need for it – the best approach would be to passcustomTitlestraight into thedialog()call, i.e.$('#MyDialog').dialog({title : customTitle});