Hi all. I have a small script that creates and removes elements from an html form. This script also renames some elements upon deletion of another element. But this does not seem to be working properly. The problem is that i can't really figure it out so i was wondering if there is a way to see the source code that is created by JavaScript, in order to track down where the problem is.

This is the code, if it's of any help:

function removeDiv(divNum){
  var container = document.getElementById("container");
  var removedID = document.getElementById("div" + divNum);
  // removing the element in the above code, so far so good

  // this loop is supposed to rename the elements that follow the deleted one
  var y = parseInt(document.getElementById("totalElements").value);
  for (i = divNum + 1; i <= y; i++){
    document.getElementById("div" + i).name = "div" + (i - 1);
    // the code below works if i delete the "for" above, and doesn't work if the "for" is there. specifically, if the added elements are 5 or more and i delete the last one, the value of y remains the same. if i delete the first or one in he middle, it works. if i delete the last and reduce the elements to 1, then add another 5 and delete the last one (as it would not work initially) it works!
    var y = parseInt(document.getElementById("totalElements").value);
    document.getElementById("totalElements").value = y - 1;
<input type="hidden" name="totalElements" />

The value of totalElements increases every time an element is added and this works well.

visual studio .net has builtin javascript debugger, so you can watch the values at runtime line by line.

commented: A dumb, wrong answer. -2
commented: please stop whoring .net all over the place, it has nothing to do with the questions being asked -1