Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    49
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Cant display image in div element

    I am trying to show the user's picture when they press a submit button, but the picture does not show up. Is it even possible for images to be displayed in a div?

    Code:
    Javascript
        function show_message()
        {
            $.post(site_url},
            		function(data)
            		{
            	        $('<img>', {src: source of pic}).appendTo($('#chatContents'));
            	    }, "json");
        }
    
    HTML
        <div id="chat-wrap">
            <div id="chatContents"></div>
        </div>

  • #2
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    While I personally don't have the answer for you, as I am still developing my JavaScript skills, you can check out this link (if you haven't already) where another user was trying to do something very similar:
    http://www.designerstalk.com/forums/...avascript.html

  • #3
    New Coder
    Join Date
    Aug 2011
    Posts
    49
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Sure I will take a look. Thanks for the link.

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,789
    Thanks
    6
    Thanked 1,022 Times in 995 Posts
    Uhm, it looks like you have a syntax error:

    Code:
    $.post(site_url},
    Also, if checking JS functionality, learn to make use of a debugging tool/error console. This would probably have notified you of the error. Firefox has a built-in error console under “Extras > Web developer” or something like that (keyboard shortcut Cmd/Ctrl+Shift+K). But there’s also the web developer toolbar and Firebug, the most popular add-on. Other browsers like Safari/Chrome or Opera have similar tools built in already.

  • #5
    New Coder
    Join Date
    Aug 2011
    Posts
    49
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Oops lol. Thanks for pointing that out.

    I fixed that, and i was using Firebug right from the start. I get no errors even though no images are showing up.
    Last edited by capypara; 12-19-2011 at 03:06 AM.

  • #6
    New Coder
    Join Date
    Aug 2011
    Posts
    49
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok i solved it, stupid mistake on my part. I forgot to json encode my data in my php, which caused JS to skip the whole function together.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •