I know there are probably other ways of doing this but i am really wondering why this code is not working properly. It does somewhat reverse stuff but the output it wrong. The idea is simply to type in a string in the textbox and when pressed on the button it should be reversed and in this case shown in an alertbox.
<input type="text" id="invoer"><input type="button" value="Display" onclick="reverseString()">
<script>
function reverseString() {
var length = document.getElementById("invoer").value.length;
var reverse = new String;
for(i=length-1;i>=0;i--) {
reverse += document.getElementById("invoer").value.substring(i,1);
}
alert(reverse);
}
</script>