0

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.

0

4 Answers 4

1

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() ,...

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry that was my own error there was a . in there. Still doesn't load.
0

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.

1 Comment

I knew I had missed out something, you are a life saver, thanks to everyone for their helpful contributions :)
0
}).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"

Comments

0

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");
    }); 

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.