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
    Dec 2011
    Posts
    59
    Thanks
    51
    Thanked 1 Time in 1 Post

    ONCLICK....post new image in DIV

    from my spry sub.menu tab,
    i'm trying to use "onclick" to post a new img in a specific div elsewhere on the page.

    <li><a class="MenuBarItemSubmenu" href="#">CPQC</a>
    <ul>
    <li><a href="#" onclick="document.getElementById('cpqcRange').src='images/cpqc/cpqcHot.png';">Hot</a></li>
    </ul>
    </li>

    <div id="cpqcRange">
    <p>
    <img src="cpqcLocation.png" alt="cpqcLocation" name="cpqcLocation" width="504" height="360" id="cpqcLocation" />
    </p>
    </div>

    i think i'm close, but something is wrong.
    can you just call up the div "cpqcRange" by name and slap a new img.src in there???????

    cheers,
    Paul

    today's weather in Kalispell, MT, USA
    cold, brrrrr, not much snow, but it's coming soon
    it was about 18degF this morning
    Last edited by Paul Williams; 12-09-2011 at 02:50 AM.

  • #2
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,675
    Thanks
    22
    Thanked 1,827 Times in 1,811 Posts
    Hello Paul Williams,
    Maybe this simple js switcher would work for you - http://nopeople.com/CSS%20tips/new_e...her/index.html

    You are colder in Kalispell than we are in Palmer today.
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #3
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,335
    Thanks
    5
    Thanked 363 Times in 360 Posts
    Hi Paul, welcome.

    Yeah thats gonna take some javascript. Anytime you want something in a webpage to "change" it will take something other than static html, which is very limited.

    Since you just finished that Missing Manual book, WOW btw! lol

    You should look into the built in snippets panel in DW where you can find lots of javascript code snippets.
    Teed

  • #4
    New Coder
    Join Date
    Dec 2011
    Posts
    59
    Thanks
    51
    Thanked 1 Time in 1 Post
    thanks Excavator, i'll check out the link

    thanks Teedoff, i'll check into the snippets and start boning up on javascript.
    i did find "showimage()" in javascript, but will have to chase it down and study the sintax.

  • #5
    New Coder
    Join Date
    Nov 2011
    Location
    New England
    Posts
    62
    Thanks
    0
    Thanked 10 Times in 10 Posts
    Quote Originally Posted by Paul Williams View Post
    from my spry sub.menu tab,
    i'm trying to use "onclick" to post a new img in a specific div elsewhere on the page.

    <li><a class="MenuBarItemSubmenu" href="#">CPQC</a>
    <ul>
    <li><a href="#" onclick="document.getElementById('cpqcRange').src='images/cpqc/cpqcHot.png';">Hot</a></li>
    </ul>
    </li>

    <div id="cpqcRange">
    <p>
    <img src="cpqcLocation.png" alt="cpqcLocation" name="cpqcLocation" width="504" height="360" id="cpqcLocation" />
    </p>
    </div>

    i think i'm close, but something is wrong.
    can you just call up the div "cpqcRange" by name and slap a new img.src in there???????

    cheers,
    Paul

    today's weather in Kalispell, MT, USA
    cold, brrrrr, not much snow, but it's coming soon
    it was about 18degF this morning
    So when you click on something, you want to add a new image to a div?

    Add jQuery to your page and try this:

    Code:
    <script type='text/javascript'>
    $(document).ready(function () 
    { 
    
    $('#TRIGGER').click(function () //change TRIGGER to the ID of the link.  Or you can make below this a function and call it with onclick
    {
    $('#cpqcRange').append("<img src='/path/to/image.jpg'>");
    });
    
    
    });
    </script>
    Easy as that. That will append the text to the end of the div that has the ID is cpqcRange.

    If you want to change the src of an image already there:
    Code:
    $('#image').attr('src','/path/to/image.jpg');
    Last edited by mvmacd; 12-09-2011 at 04:23 PM. Reason: code fix
    For programming information, visit irnsystems.com
    Also check out Points2Survey and earn items.

  • Users who have thanked mvmacd for this post:

    Paul Williams (12-09-2011)

  • #6
    New Coder
    Join Date
    Dec 2011
    Posts
    59
    Thanks
    51
    Thanked 1 Time in 1 Post
    thank you Mvmacd

    got it worked out.



  •  

    Posting Permissions

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