FoxInFlame FoxInFlame - 1 month ago 15
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.

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

Answer

Set you button type to button.

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

This will stop it from submitting your form.

See this fiddle: http://jsfiddle.net/512p1L89/


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.

Comments