Insert a file name in the src part of an iframe statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • griffo42
    New Member
    • Nov 2011
    • 3

    Insert a file name in the src part of an iframe statement

    Here is the javascript I have written and part of the XHTML but it doesn't work.
    Code:
    <script type="text/javascript">
    <!--function CalcMonth() -->
    {
    var mydate=new Date();
    var month=mydate.getMonth();
    var montharray=new Array('janstats.html','febstats.html','mar','apr','may','jun','jul','aug','sep','oct',"novstats.html",'dec');
    var fyyle="";
    fyyle=(montharray[month]);
    document.write(fyyle);
    }
    </script>
    </head>
    <body>
    <p><iframe src="'fyyle'" style="width:840px; height:1000px; border:none; margin-left:365px;"></iframe></p>
    </div> -->
    </body>
    </html>
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    a) it’s not XHTML (you would see an XHTML error)
    b) <!--* is not valid JavaScript syntax


    * - HTML commenting JavaScript code was required back in the old days of IE 3, where browsers would treat JS code as text. nowadays, no browser will do that mistake.

    Comment

    • griffo42
      New Member
      • Nov 2011
      • 3

      #3
      Thanks for your response. However, what I need to know is how to place the filename selected at line 8 into the iframe statement at line 14. Please help

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        something along
        Code:
        document.write('<iframe src="' + CalcMonth() + '"></iframe>');

        Comment

        • griffo42
          New Member
          • Nov 2011
          • 3

          #5
          Thanks to Dormilich. Your 2nd answer allowed me to get my problem sorted out. It now works fine.

          Griffo42

          Comment

          Working...