Input Feld löschen

hoctar

Erfahrenes Mitglied
Hallo :)
Ich habe folgendes Formular.

HTML:
<script type="text/javascript">
<!--
  function removeInput() {
       document.getElementsByName("standard[]")[1] = null;
  }
//-->
</script>

<input type="text" name="standard[]" value=""><br>
<input type="text" name="standard[]" value=""><br>
<a href="#" onClick="removeInput();">DEL</a>

Ich möchte durch ein klick auf DEL ein Input Feld löschen.

Ich habe es bereits so ausprobiert:
Code:
document.getElementsByName("standard")[1].remove();
delete document.getElementsByName("standard")[1];

hat leider nix funktioniert.

EDIT:

Eine Lösung wäre das hier:
HTML:
<script type="text/javascript">
<!--
  function removeInput(id) {
      InputObj = document.getElementsByName("standard[]")[1];
       document.getElementById('form').removeChild(InputObj);
  }
//-->
</script>
<form id="form">
 <input type="text" name="standard[]" value=""><br>
 <input type="text" name="standard[]" value=""><br>
 <a href="#" onClick="removeInput();">DEL</a>
</form>

Aber gibt es eine Lösung ohne den Form Knoten anzusprechen ?
 
Zuletzt bearbeitet:
Hi,

verwende hierfür parentNode.
Code:
      InputObj = document.getElementsByName("standard[]")[1];
      InputObj.parentNode.removeChild(InputObj);

Ciao
Quaese
 
Zurück