---
title: "How to change image on change url in textbox using jquery?"  
description: "How to change image on change url in textbox using jquery?"  
author: "Anonymous User"  
published: 2015-02-23  
updated: 2015-02-23  
canonical: https://www.mindstick.com/forum/12974/how-to-change-image-on-change-url-in-textbox-using-jquery  
category: "javascript"  
tags: ["jquery"]  
reading_time: 2 minutes  

---

# How to change image on change url in textbox using jquery?

Hi I’m [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to change [image](https://www.mindstick.com/articles/23551/an-investigate-distinctive-seafood-restaurant-for-your-image-stamp-character) according to [url](https://www.mindstick.com/forum/436/url-redirection) on textbox.

**This is my [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):**

```
<input type="text" name="org_img" id="org_img" class="input-xlarge" placeholder="/Images/default-1.jpg" value="/Images/default-1.jpg" />        <span class="pull-right" id="img_logo">            <img src="/Images/default-1.jpg" />        </span>  function IsValidImageUrl(url, callback) {        jQuery("<img>", {            src: url,            error: function () { callback(1); },            load: function () { callback(0); }        });    }     jQuery('#org_img').change(function () {        var img_name = jQuery('#org_img').val();        IsValidImageUrl(img_name, function (val) {            if (val == 0)                jQuery('#img_logo').html('<img src="' + img_name + '" width="300px" height="80px" />');            if (val == 1)                alert('Please Provide Valid URL Image');            jQuery('#img_logo').html('<img src="/Images/default-1.jpg" />');        });    });
```

But this code is not work proper what’s problem I don’t know.

Please [solve this problem](https://answers.mindstick.com/qa/94681/my-google-assistant-shows-completely-different-search-results-from-what-i-ask-how-can-i-solve-this-problem).

[Thank you in advance](https://answers.mindstick.com/qa/40482/why-was-1968-a-year-of-tension-and-turmoil-list-10-events-1-being-the-best-and-10-the-worst-thank-you-in-advance).

## Replies

### Reply by Anonymous User

Try this code I think this solution is solve your [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic)

```
<input type="text" name="org_img" id="org_img" value="/Images/default-1.jpg" />         <span id="img_logo">            <img id="image_logo" src="/Images/default-1.jpg" /></span>function IsValidImageUrl(url, callback) {        jQuery("<img>", {            src: url,            error: function () { callback(1, null); },            load: function () { callback(0, url); }        });    }     $('#org_img').change(function () {        var img_name = $(this).val();        IsValidImageUrl(img_name, function (val, url) {            if (val == 0) {                $('#image_logo').attr('src', url);            }            if (val == 1) {                alert('Please Provide Valid URL Image');                $('#image_logo').attr('src', "/Images/default-1.jpg");            }        });   
});
```


---

Original Source: https://www.mindstick.com/forum/12974/how-to-change-image-on-change-url-in-textbox-using-jquery

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
