FoxInFlame FoxInFlame - 10 days ago 4
Javascript Question

Getting Minecraft Images

I am trying to make something, where, if you input your minecraft username, you get your profile icon.

I found this website Minotar, where you could get icons by the url. So, I tried making a JavaScript script out of it, and display it. But, the picture doesn't want to show up when I click "Go!".

What have I done wrong?

Here is my code.

function usernameget(){
var username = document.getElementById("username").value;
var url = "" + username + "/150";
document.getElementById("usernamepicture").setAttribute("src", url);
<img id="usernamepicture" src="">
<p>Your Minecraft Username</p>
<input type="text" id="username">
<button onclick="usernameget()">Go!</button>


Set you button type to button.

<button onclick="usernameget()" type="button">Go!</button>

This will stop it from submitting your form.

See this fiddle:

However I think the better solution would be to remove the form tag unless you do require the user to later submit the form back to the server.