Use search box for change image with javascript

80 views Asked by At

What should happen is that if I search for "HAlexer" using search box the image will be

"http://site/avatar/200/NICKNAME" (where NICKNAME will be "HAlexer")

Demo

JavaScript code:

$(document).ready(function() {
var SITE_URL = "http://site/";
var JSON = SITE_URL+"json/";
var interval_BeautifulCounter;
var counterRequest;

$('#user-search-butt').click(function() {
    var username = $('#user-search').val();
    if (username !== '') {
        DisplayUsersInfo(username);
    } else {
        ShowAlert('Username cannot be empty!', 'danger');
    }
});
function DisplayUsersInfo(username) {{
                    // Title
                    $('#modal-username-title').html(data.username);
                    // Avatar
                    $('#modal-img-avatar').attr('src', SITE_URL+'avatar/256/'+data.username);
                    $('#modal-img-avatar').attr('alt', data.username+' avatar');
                    $('#modal-img-avatar').attr('title', data.username+' avatar');
                    $('#modal-input-avatar').val(SITE_URL+'avatar/'+data.username);
                    // Skin
                    $('#modal-img-skin').attr('src', SITE_URL+'skin/256/'+data.username);
                    $('#modal-img-skin').attr('alt', data.username+' skin');
                    $('#modal-img-skin').attr('title', data.username+' skin');
                    $('#modal-input-skin').val(SITE_URL+'skin/'+data.username);
                    // Skin Back
                    $('#modal-img-skin-back').attr('src', SITE_URL+'skin-back/256/'+data.username);
                    $('#modal-img-skin-back').attr('alt', data.username+' skin back');
                    $('#modal-img-skin-back').attr('title', data.username+' skin back');
                    $('#modal-input-skin-back').val(SITE_URL+'skin-back/'+data.username);
                    // buttons
                    $('#modal-btn-user').attr('href', SITE_URL+'user/'+data.username);
                    $('#modal-btn-download').attr('href', SITE_URL+'download/'+data.uuid);
                    $('#modal-btn-change').attr('href', 'http://www.minecraft.net/skin/remote.jsp?url='+SITE_URL+'skins/'+data.uuid+'.png');
                    $('#user-info-modal').modal('show');
                }
                }
            });
    } else {
        ShowAlert('Alert!', 'danger');
    }
}
    return true;
}
});
1

There are 1 answers

1
Pierre Espenan On BEST ANSWER

In your DisplayUsersInfo function, you shouldn't use data.username but just username.

Also, since your input field has the ID #username, I think your line

var username = $('#user-search').val();

should be

var username = $('#username').val();

Your jQuery selector $('#user-search') doesn't seem to refer to anything in the code you posted.