forum

home / developersection / forums / how to change image on change url in textbox using jquery?

How to change image on change url in textbox using jquery?

Anonymous User 2356 23-Feb-2015

Hi I’m trying to change image according to url on textbox.

This is my code:

<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.

Thank you in advance.


Updated on 23-Feb-2015

I am a content writter !


Message
Can you answer this question?

Answer

1 Answers

Liked By