SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    update img src url when user enteres url in an input box

    im trying to update the part of this img src

    <img src"http://www.artviper.net/screenshots/screener.php?url=http://www.mydomain.com/&w=300&q=10"/>

    where it says http://www.mydomain.com/, when a user enters a different site url in an input box.... is that possible with javascript?

  2. #2
    SitePoint Evangelist
    Join Date
    Mar 2006
    Location
    Sweden
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Add an onkeyup-event to an input box, something like:
    Code:
    <html>
    <head>
    <script type="text/javascript">
    window.onload = function()
    {
    	document.getElementById( 'inp' ).onkeyup = keyUp;
    }
    
    function keyUp()
    {
    	var img = document.getElementById( 'image' );
    	img.src = img.src.replace( /url=[^&]+/, 'url='+ this.value );
    }
    </script>
    </head>
    <body>
    	<input type="text" id="inp">
    
    	<img id="image" src="http://www.artviper.net/screenshots/screener.php?url=http://www.mydomain.com/&w=300&q=10">
    </body>
    </html>

  3. #3
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    would this leave the

    &w=300&q=10

    after the url... and what do you mean add an onkeyup-event to an input box? cuz its not working right now

    thanks

  4. #4
    SitePoint Evangelist
    Join Date
    Mar 2006
    Location
    Sweden
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yup, it leaves those query strings. What is not working right now? I tested it in Firefox, and it worked fine.

  5. #5
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nevermind, it worked. my computer is just really really slow, so it was taking a while for the image to refresh

    thanks a lot


Bookmarks

Posting Permissions

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