Reputation: 359
I am using a form to submit details to a page which create an image, the form is submitted using Jquery so that the user does not have to leave the page. The send() function calls on the refresh() function to update the div where the image is placed into...
I am having an issue with one of the lines of code of my code and I don't know what to put to get it to work:
function refresh()
{
$(function () {
var img = new Image();
$(img).load(function () {
//$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
$(this).hide();
$('#loader').removeClass('loading').append(this);
$(this).fadeIn();
}).error(function () {
// notify the user that the image could not be loaded
// The next line causes the error
}).attr('src', "signatures/" +$("#username") "png");
});
}
Any help would be appreciated.
Upvotes: 0
Views: 3864
Reputation: 69905
Try this
function refresh()
{
$(function () {
var img = $("<img />").appendTo(document.body);
$(img).load(function () {
//$(this).css('display', 'none'); // .hide() doesn't work in Safari when the element isn't on the DOM already
$(this).hide();
$('#loader').removeClass('loading').append(this);
$(this).fadeIn();
}).error(function () {
// notify the user that the image could not be loaded
// The next line causes the error
}).attr('src', "signatures/" +$("#username")+ ".png");
});
}
Upvotes: 0
Reputation: 75993
}).attr('src', "signatures/" +$("#username") "png");
You are passing a dom object, $("#username"). If the 'username' element is a textbox, you can use:
$("#username").val() + ".png"
And if it is a div or some other type of container you can use:
$("#username").text() + ".png"
Upvotes: 0
Reputation: 13549
looks like you need + $("#username").val() + ".png")
instead of +$("#username") "png")
This assumes that username is an id of some sort of hidden input field. replace val()
with something else accordingly.
Upvotes: 0
Reputation: 4753
you horgot the dot before the extention:
.attr('src', "signatures/" +$("#username") "png");
should be:
.attr('src', "signatures/" +$("#username") ".png");
if $("#username")
is a value.
you might need a .html() / .text or .val() ,...
Upvotes: 1