I am trying to select an input field’s value inside modal window.
function title()
{
$('a.title_filestock').click(function(e) {
e.preventDefault();
var data = $(this).children('img').attr('rel');
var active = $(this).next('a.filestock_preview');
var value = active.text();
new VayesModal('<label for=Display Name"><input id="'+data+'" type="text" size="12" value="'+$.trim(value)+'" />', { modal: true, modalOpacity: '.5', title: 'Type File Display Name', titleClass: 'anim warning', buttons: [{id: 0, label: 'Save', val: 'Y', btnClass: 'btn-success'}, {id: 1, label: 'Cancel', val: 'N', btnClass: 'btn-danger'}], callback: function(val) { if(val == 'Y') { alert($('input[id="'+data+'"]').val()); active.text('new string'); } else return false; }});
});
}
title();
“new string” should be $('input[id="'+data+'"]').val() but it returns undefined. I might make a mistake?
problem is, that
callback:function(val) {
dont have access to local “data” variable (defined) from function title()
try alert(data) and this will be also undefined.
try what console.log($(this)) will returns, because this must be any parent object (probably some ModalWindow object) and maybe you can add “data” variable into this and load from in callback
}
I didnt found any existing VayesModal library on google, so I cant help you more.
Try http://jqueryui.com/demos/dialog/#modal-form
little hint:
$(‘input[id=”‘+data+'”]’) equals to $(‘input#”‘+data)
EDIT:
Found it 🙂 Callback is called after modal window is removed, so input doesnt exists yet. Go to messi.js, method
Messi.prototype.hide(after) { and move “”if (after) after.call(); “” to first line in this.messi.animate…function, before .remove() }
BUT keep in mind, that you changed plugin source code.
(VayesModal is Messi plugin. )