Ankündigung

Einklappen
Keine Ankündigung bisher.

Vorgabewert bei Select

Einklappen

Neue Werbung 2019

Einklappen
X
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • Vorgabewert bei Select

    Hallo,
    habe im PHP-Script eine Select-Box. Wie kann ich der sagen welches der Vorgabewert $tp_rubrik ist?
    <select name="rubrik">
    <option>Access</option>
    <option>Word</option>
    <option>Excel</option>
    <option>PowerPoint</option>
    <option>Outlook</option>
    <option>VBA Allg.</option>
    <option>Visual Basic</option>
    </select>

    Gruß Andreas

  • #2
    Code:
    <?
    echo ($tp_rubrik == "Access") ? '<option selected="yes">Access</<option>'  : '<option>Access</option>';
    usw...
    ?>
    mit dieser Konstruktion kannst du If-Abfragen schneller gestalten als mit
    Code:
    if (TEST) {
    //
    }
    else{
    //
    }
    Du kannst zum Bleistift schnell entscheiden ob sell oder jener Text in einer Variable gespeichert wird:
    Code:
    $varaible (TEST) ? RICHTIG : FALSCH
    mfg,
    Jojo

    Kommentar


    • #3
      <edit>

      Hallo,
      danke für den Code, hat super geklappt:

      Code:
      <select name="rubrik">';
      echo ($tp_rubrik == "Access") ? '<option selected="yes">Access</<option>'  : '<option>Access</option>'; 
      echo ($tp_rubrik == "Word") ? '<option selected="yes">Word</<option>'  : '<option>Word</option>'; 
      echo ($tp_rubrik == "Excel") ? '<option selected="yes">Excel</<option>'  : '<option>Excel</option>'; 
      echo ($tp_rubrik == "PowerPoint") ? '<option selected="yes">PowerPoint</<option>'  : '<option>PowerPoint</option>'; 
      echo ($tp_rubrik == "Outlook") ? '<option selected="yes">Outlook</<option>'  : '<option>Outlook</option>'; 
      echo ($tp_rubrik == "VBA Allg.") ? '<option selected="yes">VBA Allg.</<option>'  : '<option>VBA Allg.</option>'; 
      echo ($tp_rubrik == "Visual Basic") ? '<option selected="yes">Visual Basic</<option>'  : '<option>Visual Basic</option>';
      echo '</select>';
      Gruß Andreas

      Kommentar


      • #4
        ich hab übrigens grad bemerkt, dass man es noch ein wenig kürzer schreiben kann, wenn du in HTML bist:
        Code:
        <html>
        <body>
        <form>
        <select name="rubrik">
        <option<? echo ($tp_rubrik == "Access") ? ' selected="yes"' : ''; ?>>Access</option>
        usw...
        mfg,
        Jojo

        Kommentar


        • #5
          Wenn du sonst noch etwas über Formulare wissen willst, dieses Kapitel in dem Tutorial PHP-Q.net ist dafür super geeignet (selbstverständlich ist es besser, alle Kapitel zu lesen )
          http://tut.php-q.net/formulare.html

          Kommentar


          • #6
            Danke an alle,
            Andreas

            Kommentar

            Lädt...
            X