Stefan Neufuß: Formobjekt über variablen adressieren

Wie kann ich folgenden Javascriptcode mit einer Funktion realisieren?

function p1Switch01(x) {document.form_nvoASwitch01.NVL_nvoASwitch01.value = x + ".0 1";document.form_nvoASwitch01.submit();}

function p1Switch02(x) {document.form_nvoASwitch02.NVL_nvoASwitch02.value = x + ".0 1";document.form_nvoASwitch02.submit();}

function p1Switch03(x) {document.form_nvoASwitch03.NVL_nvoASwitch03.value = x + ".0 1";document.form_nvoASwitch03.submit();}
.....

mein modifikation funktioniert leider nicht

function Switch(x,index) {document.form_nvoASwitch[index].NVL_nvoASwitch[index].value = x + ".0 1";document.form_nvoASwitch[index].submit();}

  1. Hallo Stefan,

    function Switch(x,index) {document.form_nvoASwitch[index].NVL_nvoASwitch[index].value = x + ".0 1";document.form_nvoASwitch[index].submit();}

    z.B. so:
    document.forms["form_nvoASwitch" + index].elements["NVL_nvoASwitch" + index].value

    Grüße
    Andreas

    --
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
    (Rich Cook)