views:

57

answers:

1

Hi, If someone here is willing to help me I would really appreciate

the function removeInput() of javascript at below not work properly, what i should do?

<script language="javascript">
fields = 0;
function addInput() {
    if (fields != 10) {
        var htmlText =  "<input type='text' name='friends[]' value='' size='auto' maxlength='45' /><br />";
        var newElement = document.createElement('div');
        newElement.id = 'addfriend'; 
  newElement.innerHTML = htmlText;

        var fieldsArea = document.getElementById('addfriend');
 fieldsArea.appendChild(newElement);

        fields += 1;
    } else {
        alert("Only 10 friends allowed.");
        document.form.add.disabled=true;
    }
}
//field = 0;
function removeInput() {
  var div = document.getElementById('addfriend');
        var lastElement = document.removeElement('div');
        lastElement.id = 'addfriend'; 
  if (lastElement > 2) div.Element(lastElement - 1);

}
</script>
A: 

casablanca and mootinator are right, the code and question are not in any way helpful in understanding the purpose. But outright, I can see this problem:

var div = document.getElementById('addfriend');

var lastElement = document.removeElement('div'div);

Why are there quotes around div?.. If you are trying to remove the div object, don't put the quotes there.

Ravindra Sane
I really want to delete the column div that contains the input fields that were previously formed by type: function addInput (), so I've done what you suggest with only var lastElement = document.removeElement (div); but I do not get the result, maybe I need an example concrete.
Also, are you using any sort of library? The DOM method is document.removeChild() What does the last line [if (lastElement > 2) div.Element(lastElement - 1);] do?
Ravindra Sane
I think I'm not using sort library, the last line if (lastElement > 2) div.Element(lastElement - 1); I meant to remove the fields that are formed before, I just try to do it. and it not work then i looking for Some help here, I must appreciated your attentions and thank You.