Q:

Looping Through an Array of Characters

I would like to loop an array for a specific set of characters that is constantly changing. From there on I want to toggle case the letters, and I've been told to use this specific code but I can't get it to work. The code MUST loop through an array of characters, where the characters are coming from an "input" textbox. How can I fix this?
I should mention that I'm doing this for class in high school, so I'm no where near perfect at coding.

    <html> 
      <head> 
        <script type="text/javascript"> 
    function toggleCase() { 
        var i = document.getElementById("input").value.length;
        var word = document.getElementById("input").value;
        var chop =new array(i);
        for (a=i; a <= i; a++) {
            character[i] = word.slice(i-1,i)
            if (character[i] == character[i].toUpperCase;){
                character[i] = character[i].toLowerCase();
            }
            else {
                character[i] = character[i].toUpperCase();
            }
        }

        var final

        for (a=i; a <= i; a++) {
            final += character[i];
        }

        document.getElementById("output").value = final
    }
        </script> 
      </head> 
      <body> 
        <p>Enter letters for conversion:</p> 
        <form> 
          <input type="text" name="input" id="input" value="sample" maxlength="10"><br />
          <input type="text" name="output" id="output" value="" /> <br/>
          <input type="checkbox" name="toggle" value="ToggleCase" onClick="toggleCase(this.form)">Toggle Case<br/>
        </form> 
      </body> 
    </html> 

A:

Maybe you should take a look at some api's and howtos but here is your code:

<html> 
<head> 
<script type="text/javascript"> 
function toggleCase() { 
  var text = document.getElementById("input").value;
  var character = new Array(text.length);

  for (i=0, a = text.length; i < a; i++) {
    character[i] = text[i];
    if (character[i] == character[i].toUpperCase){
      character[i] = character[i].toLowerCase();
    }
    else {
      character[i] = character[i].toUpperCase();
    }
  }

  document.getElementById("output").value = character.join('');
}
</script> 
</head> 
<body> 
<p>Enter letters for conversion:</p> 
<form> 
<input type="text" name="input" id="input" value="sample" maxlength="10"><br />
<input type="text" name="output" id="output" value="" /> <br/>
<input type="checkbox" name="toggle" value="ToggleCase" onClick="toggleCase()">Toggle Case<br/>
</form> 
</body> 
</html> 

