Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3599746
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:24:22+00:00 2026-05-18T20:24:22+00:00

I need to allow the web user to enter a URL for an image,

  • 0

I need to allow the web user to enter a URL for an image, and I want the user to have visual confirmation that the URL is valid (or not).

I would like it so that if the user enters:

  • nothing, it will display the default (not found) image.
  • http://example.com/ValidImageUrl.any_or_no_extension, it will accept it and display the image.
  • hxxp://example.com/ValidImageUrl.any_or_no_extension, it will display the default (not found) image
  • http://example.com/INVALID_imageurl.any_or_no_extension, it will display the default (not found) image. Essentially, if the link is anything but a 200, it should display the default
  • http://example.com/asdf?qwerty&t=10982741238947, (assuming it is valid) it will automagically determine whether it is a valid image and display it if valid, otherwise display the default (not found) image. This is the hardest case to capture, but is becoming increasingly important in today’s flickr & picassa embedded world… But if the browser can detect it as an image and display it, then javascript should be able to detect it, and identify its particulars.

The following is an extremely simplified example:

<input id="GivenUrl" onblur="UpdateImage()"/>
<img id="UserImage"/>

<script type="text/javascript">
  var TextBox =  document.getElementById("GivenUrl");
  var Image = document.getElementById("UserImage");
  if (Image.value == "")
  {
    UserImage.setAttribute("src", "MyDefaultImage.jpg");
  }else{
    UserImage.setAttribute("src", encodeURI(TextBox.value));
  }
</script>

And finally my constraints: I’d optimally like the solution to be pure HTML / javascript, all processed on the client (user) side. Slightly less favorable solutions would involve .Net server-side processing, which is possible but definitely not optimal…

Any ideas?

Please overlook any benign coding errors in the above, since I am not currently at a machine where I can test my own code…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:24:23+00:00Added an answer on May 18, 2026 at 8:24 pm

    You are in luck 🙂

    Images have an onerror handler, so you don’t have to check the image’s validity (ie, the url might try to return HTML instead of image), you can still cover your back.
    Though I’m pretty sure the handler might not be W3C-approved.

    <input id="GivenUrl" onblur="UpdateImage()"/>
    <img id="UserImage" onerror="RollbackImage()"/>
    
    <script type="text/javascript">
      var TextBox =  document.getElementById("GivenUrl");
      var Image = document.getElementById("UserImage");
      var OldUrl = Image.src;
      function UpdateImage(){
        OldUrl = Image.src;
        Image.src=TextBox.value;
      }
      function RollbackImage(){
        Image.src=OldUrl;
      }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to allow the web user to enter a URL for an image,
I have a need to allow for a user to download an event that
I have a web application that I would like to allow persistent access to
I have a web app I'm creating, where I need to allow the user
I am building a web application that will need to allow users to save
I am working on a secure web site, that will allow the user to
I need code that will allow the user to do the following: Select a
I am writing a web application that will allow a user to browse to
I need to allow full-text searching on two fields that are concatenated together. In
I need to allow users to upload PDF documents that other users will read.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.