Matthias: Options eines Select Elements

Hallo. Ich habe eine Funktion die einen HTML Node übergibt. Dieser kann sowohl ein Input als auch ein Select sein.

Wenn es sein Select ist, will ich nun auf die Options des selects zu greifen.

thisField ist der Node
 function serializeField( thisField, readonly ) {
  var sel_options = eval("thisField." + options);
 }

klappt nicht. Dort bekomme ich als Meldung options is not defined. Muss ich vorher noch ein Select Element erstellen?

Danke!

  1. n'abend,

    thisField ist der Node
    function serializeField( thisField, readonly ) {
      var sel_options = eval("thisField." + options);
    }

    Was soll dieses eval() da bewirken?
    Ist dir bewusst, dass du auf die Variable thisField gar nicht zugreifst?

    klappt nicht. Dort bekomme ich als Meldung options is not defined. Muss ich vorher noch ein Select Element erstellen?

    richtig, denn die Variable options ist hier weder innerhalb der Funktion definiert, noch als Argument der Funktion spezifiziert worden.

    weiterhin schönen abend...

    --
    #selfhtml hat ein Forum?
    sh:( fo:# ch:# rl:| br:> n4:& ie:{ mo:} va:) de:] zu:} fl:( ss:? ls:[ js:|
    1. n'abend,

      thisField ist der Node
      function serializeField( thisField, readonly ) {
        var sel_options = eval("thisField." + options);
      }

      Was soll dieses eval() da bewirken?
      Ist dir bewusst, dass du auf die Variable thisField gar nicht zugreifst?

      eval() macht genau das, es interprettiert den String als Variable (oder Funktion oder... was auch immer) also wird durchaus auf "thisField" zugegriffen.
      Allerdings ist das hier völlig unnötig, was spricht gegen

      function serializeField( thisField, readonly ) {  
       var sel_options = thisField.options;  
      }
      

      Wenn ich das "Gesamtproblem", also die eigentliche Zielsetzung richtig verstanden habe würde ich gar
      var selected_option = thisField.options[thisField.selectedIndex]
      benutzen.

      --
      sh:( fo:| ch:? rl:( br:& n4:& ie:{ mo:} va:) de:µ_de:] zu:) fl:( ss:| ls:[ js:(
  2. Hi,

    Hallo. Ich habe eine Funktion die einen HTML Node übergibt. Dieser kann sowohl ein Input als auch ein Select sein.

    Wenn es sein Select ist, will ich nun auf die Options des selects zu greifen.

    Dann frage zunächst den nodeName des übergebenen HTML-Objektes ab.

    MfG ChrisB

    --
    Light travels faster than sound - that's why most people appear bright until you hear them speak.