Harry B: Einfügen von Html-code in Javascript

Hi erstmal,

ich hab leider ein kleines Problem!
Und zwar sehe ich das hoffentlich schon richtig, dass ich Html-Code in Javascript verwenden kann und zwar 1:1 (ausnahme die Anführungszeichen die man Backslashen muss), oder nicht?

Doch denke schon.

So nun habe ich mir einen html code geschrieben und ihn in eine function bei javascript eingefügt, doch er macht mir nicht das was er machen soll er bringt undefined und finde den Fehler nicht was ich hätte falsch machen können.

HIER DER HTML CODE:

<table style="border-style: solid; border-color:#ffffff; border-width:5; background:#C5C5C5;" width="100" cellspacing="0" cellpadding="0">
  <tr>
    <td height="1"></td>
  </tr>
</table>

NUN IN JAVASCRIPT AUFGENOMMEN:

function menuLine (){
var sCode =""
sCode += " <table style="border-style: solid; border-color:#ffffff; border-width:5; background:#C5C5C5;" cellspacing="0" cellpadding="0">";
sCode += "  <tr>";
sCode += "   <td height="1"></td>";
sCode += "  </tr>";
sCode += " </table>";
}

UND NUN DAS AUFRUFEN DER FUNKTION (KOMPLETT SCHAUTS DANN SO AUS):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
 <title>Menu_System</title>
<script>
function menuLine (){
var sCode =""
sCode += " <table style="border-style: solid; border-color:#ffffff; border-width:5; background:#C5C5C5;" cellspacing="0" cellpadding="0">";
sCode += "  <tr>";
sCode += "   <td height="1"></td>";
sCode += "  </tr>";
sCode += " </table>";
}
</script>
<table>
 <script>
  print(menuLine ());
 </script>
</table>
</head>

<body>

</body>
</html>

Darum bitte ich um eure Hilfe, das wäre super.

Vielen Dank schon mal im voraus.

  1. Sry ich habe die print function vergessen

    HIER IST SIE:

    function print (sText){
     document.writeln(sText);
    }

    UND NUN DAS AUFRUFEN DER FUNKTION (KOMPLETT SCHAUTS DANN SO AUS):

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>
    <head>
    <title>Menu_System</title>
    <script>
    function print (sText){
     document.writeln(sText);
    }

    function menuLine (){
    var sCode =""
    sCode += " <table style="border-style: solid; border-color:#ffffff; border-width:5; background:#C5C5C5;" cellspacing="0" cellpadding="0">";
    sCode += "  <tr>";
    sCode += "   <td height="1"></td>";
    sCode += "  </tr>";
    sCode += " </table>";
    }

    </script>
       <table>
       <script>
          print(menuLine ());
       </script>
    </table>
    </head>

    <body>

    </body>
    </html>

    1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

      <html>
      <head>
      <title>Menu_System</title>
      <script>

      <script type="text/javascript">

      function print (sText){
      document.writeln(sText);
      }

      function menuLine (){
      var sCode =""
      sCode += " <table style="border-style: solid; border-color:#ffffff; border-width:5; background:#C5C5C5;" cellspacing="0" cellpadding="0">";
      sCode += "  <tr>";
      sCode += "   <td height="1"></td>";
      sCode += "  </tr>";
      sCode += " </table>";
      }

      einmal kannst du dir die ganze maskiererei sparen aber du musst die schliessenden / maskieren, außderm solltest du sCode auch zurückgeben.

      function menuLine (){
      return ' <table style="border-style: solid; border-color:#ffffff; border-width:5; background:#C5C5C5;" cellspacing="0" cellpadding="0">'

      • '  <tr>'
      • '   <td height="1"></td>';
      • '  </tr>'
      • ' </table>';
        }

      </script>

      <table>
         <script>
            print(menuLine ());
         </script>
      </table>

      <table>
      ist nicht nötig und selbst wenn es fehlen tr und td

      </head>

      und im head darf das natürlich auch nicht stehen, sondern im body.

      Struppi.

      1. Hi Struppi

        Vielen herzlichen dank,
        hast mir super weitergeholfen.
        Thx. Ciao