Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Functions not working...

    Hello!

    I am currently in a class learning how to use functions and javascript in HTML coding. A particular task is having me use functions. The problem is that the functions just aren't working. No matter what I review in the textbook or through google, they simply don't work. I would be very grateful if anyone can assist me in this issue.

    The code for the functions are as follows:

    Code:
    <script type="text/javascript">
    
    function scrollColor() {
    	styleObject=document.getElementsByTagName(‘html’)[0].style
    	styleObject.scrollbarFaceColor=“#be1e20”
    	styleObject.scrollbarTrackColor=“#000000”
    }
    
    function loadInfo(announceMenu) {
    	var menuSelect=myForm.Menu.selectedIndex
    	var menuUrl=myForm.Menu.options[menuSelect].value+“.html”
    	window.location=announceMenu
    }
    
    function copyRight() {
    	date=document.lastModified 
    	day=date.charAt(3)+date.charAt(4) 
    	month=date.charAt(0)+date.charAt(1) 
    	year=date.charAt(6)+date.charAt(7)+date.charAt(8)+date.charAt(9) 
    	document.write("The URL of this document is file //G//XHTML6F\Chapter09\Solutions\InTheLab\lab9-1solutions.html")
    	document.write("St. Michael's Hospital")
    	document.write("This document was last modified "+day+"/"+month+"/"+year) 
    
    </script>
    I really don't understand why NONE of this works. Even the colored scroll bar doesn't actually work. I tried viewing it with IE9 and it still has no changes. What am I missing?

  • #2
    Regular Coder
    Join Date
    Mar 2013
    Posts
    262
    Thanks
    4
    Thanked 67 Times in 67 Posts
    First, your copyRight function doesn't have a closing curly brace. I suggest adding that. Once you do that...

    Open up your browser. Press F12. Modern browsers come with this developer tool. This is going to help you so much when you're working with JavaScript.

    When you press F12, there should be several tabs. Go to Console. This section is like a debugging tool for JavaScript. This is going to help you so much in the future and in your class. Use it whenever you work with JavaSript.

    Anyway, basically, your problem is this. First error:

    Code:
    styleObject=document.getElementsByTagName(‘html’)[0].style
    The problem is the single quotation mark (or apostrophe). I'm guessing you typed this up on Microsoft Word or copied it from a source like that. You need to use a text editor like Notepad or even better, Notepad++ (click here to download).

    Take a look and tell me if you notice a difference:

    Yours: ‘
    Mine: '

    Your quotation marks (both single and double) are not in plain text. I also suggest not omitting semicolons. Change them and then try again.
    Last edited by ttkim; 04-09-2013 at 06:05 AM.
    My signature :)

  • #3
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the input! I checked it over and you are indeed right. I am using an eBook for my textbook and it said I could use some code within the textbook for reference. I copy and pasted and never would've thought the quotations were crazy. I also didn't know of the F12 thing. I scoped that over and fixed the errors. However, the colored scroll bar still isn't working for me. There is no more errors within the F12 list anywhere.

    Using IE9, it says that I can view the webpage by allowing ActiveX. I of course select yes. It used to be that it reloaded the webpage and there was nothing new. NOW, however, the ONLY thing there is the result of this function:

    [code]function copyRight() {
    date=document.lastModified
    day=date.charAt(3)+date.charAt(4)
    month=date.charAt(0)+date.charAt(1)
    year=date.charAt(6)+date.charAt(7)+date.charAt(8)+date.charAt(9)
    document.write("The URL of this document is file //G//XHTML6F\Chapter09\Solutions\InTheLab\lab9-1solutions.html")
    document.write("St. Michael's Hospital")
    document.write("This document was last modified "+day+"/"+month+"/"+year)
    }[code]

    Which connects with...

    [code]</table>
    <p></p>
    <div id="displayCopyRight"></div>
    </body>
    </html>[/quote]

    I included the non-DIV bits of code to give you a rough idea of where it's placed. This is actually where the textbook told me to place it. So what happens when I allow ActiveX is only seeing text and nothing else (website gone entirely elsewise) saying: The URL of this document is file //G//XHTML6FChapter09SolutionsInTheLablab9-1solutions.htmlSt. Michael's HospitalThis document was last modified 08/04/2013

    The new function code altogether:

    [code]<script type="text/javascript">

    function scrollColor() {
    styleObject=document.getElementsByTagName('html')[0].style
    styleObject.scrollbarFaceColor="#be1e20"
    styleObject.scrollbarTrackColor="#000000"
    }

    function loadInfo(announceMenu) {
    var menuSelect=myForm.Menu.selectedIndex
    var menuUrl=myForm.Menu.options[menuSelect].value+“.html”
    window.location=announceMenu
    }

    function copyRight() {
    date=document.lastModified
    day=date.charAt(3)+date.charAt(4)
    month=date.charAt(0)+date.charAt(1)
    year=date.charAt(6)+date.charAt(7)+date.charAt(8)+date.charAt(9)
    document.write("The URL of this document is file //G//XHTML6F\Chapter09\Solutions\InTheLab\lab9-1solutions.html")
    document.write("St. Michael's Hospital")
    document.write("This document was last modified "+day+"/"+month+"/"+year)
    }

    </script>[/quote]

    You mentioned to not omit semi-colons. My friend, where would these even go to begin with?

    I greatly appreciate the help. This whole thing has been very frustrating for me.

    P.S: I also tried viewing the HTML file in Chrome and it's pretty much the same thing as IE9 minus the ActiveX thing.

  • #4
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Whoops. Previous reply is all kinds of messed up. I wanted to fix it but... I can't seem to find the edit button?

    I'm replying again with the fixed version for ease of reading. Sorry about that.

    _________________


    Thanks for the input! I checked it over and you are indeed right. I am using an eBook for my textbook and it said I could use some code within the textbook for reference. I copy and pasted and never would've thought the quotations were crazy. I also didn't know of the F12 thing. I scoped that over and fixed the errors. However, the colored scroll bar still isn't working for me. There is no more errors within the F12 list anywhere.

    Using IE9, it says that I can view the webpage by allowing ActiveX. I of course select yes. It used to be that it reloaded the webpage and there was nothing new. NOW, however, the ONLY thing there is the result of this function:

    Code:
    function copyRight() {
    	date=document.lastModified 
    	day=date.charAt(3)+date.charAt(4) 
    	month=date.charAt(0)+date.charAt(1) 
    	year=date.charAt(6)+date.charAt(7)+date.charAt(8)+date.charAt(9) 
    	document.write("The URL of this document is file //G//XHTML6F\Chapter09\Solutions\InTheLab\lab9-1solutions.html")
    	document.write("St. Michael's Hospital")
    	document.write("This document was last modified "+day+"/"+month+"/"+year) 
    }
    Which connects with...

    Code:
    </table>
    <p></p>
    <div id="displayCopyRight"></div>
    </body>
    </html>
    I included the non-DIV bits of code to give you a rough idea of where it's placed. This is actually where the textbook told me to place it. So what happens when I allow ActiveX is only seeing text and nothing else (website gone entirely elsewise) saying: The URL of this document is file //G//XHTML6FChapter09SolutionsInTheLablab9-1solutions.htmlSt. Michael's HospitalThis document was last modified 08/04/2013

    The new function code altogether:

    Code:
    <script type="text/javascript">
    
    function scrollColor() {
    	styleObject=document.getElementsByTagName('html')[0].style
    	styleObject.scrollbarFaceColor="#be1e20"
    	styleObject.scrollbarTrackColor="#000000"
    }
    
    function loadInfo(announceMenu) {
    	var menuSelect=myForm.Menu.selectedIndex
    	var menuUrl=myForm.Menu.options[menuSelect].value+“.html”
    	window.location=announceMenu
    }
    
    function copyRight() {
    	date=document.lastModified 
    	day=date.charAt(3)+date.charAt(4) 
    	month=date.charAt(0)+date.charAt(1) 
    	year=date.charAt(6)+date.charAt(7)+date.charAt(8)+date.charAt(9) 
    	document.write("The URL of this document is file //G//XHTML6F\Chapter09\Solutions\InTheLab\lab9-1solutions.html")
    	document.write("St. Michael's Hospital")
    	document.write("This document was last modified "+day+"/"+month+"/"+year) 
    }
    
    </script>
    You mentioned to not omit semi-colons. My friend, where would these even go to begin with?

    I greatly appreciate the help. This whole thing has been very frustrating for me.

    P.S: I also tried viewing the HTML file in Chrome and it's pretty much the same thing as IE9 minus the ActiveX thing.

  • #5
    Regular Coder
    Join Date
    Mar 2013
    Posts
    262
    Thanks
    4
    Thanked 67 Times in 67 Posts
    JavaScript basically adds/guesses when to put semicolons. To prevent it from incorrectly guessing it, you should tell the browser every time you finish a command. So...

    Code:
    styleObject=document.getElementsByTagName('html')[0].style;
    That is one command so I put a semicolon at the end.

    Anyway, I'm not entirely sure what the problem is. Actually, I never got an ActiveX prompt. Two of the 3 functions work for me, but I have no idea what loadInfo is doing. Actually seems like it should be more like this (but not sure):

    Code:
    function loadInfo(myForm) {
    	var menuSelect=myForm.Menu.selectedIndex;
    	var menuUrl=myForm.Menu.options[menuSelect].value+".html";
    	window.location=menuUrl;
    }
    Anyway, if something isn't working, try posting the whole code. Maybe I (or someone else) can help better.
    My signature :)

  • #6
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK, sure. I didn't post the whole code initially because I didn't want to seem like the kind of guy that comes on these types of forums and says "here do my homework". The whole code is as follows:

    Code:
    <!DOCTYPE html
       PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-type" content="text/html;charset=UTF-8" /> 
    <title>Lab 9-1solution</title>
    <script type="text/javascript">
    
    function scrollColor() {
    	styleObject=document.getElementsByTagName('html')[0].style;
    	styleObject.scrollbarFaceColor="#be1e20";
    	styleObject.scrollbarTrackColor="#000000";
    }
    
    function loadInfo(announceMenu) {
    	var menuSelect=myForm.Menu.selectedIndex;
    	var menuUrl=myForm.Menu.options[menuSelect].value+“.html”;
    	window.location=announceMenu;
    }
    
    function copyRight() {
    	date=document.lastModified ;
    	day=date.charAt(3)+date.charAt(4);
    	month=date.charAt(0)+date.charAt(1);
    	year=date.charAt(6)+date.charAt(7)+date.charAt(8)+date.charAt(9); 
    	document.write("The URL of this document is file //G//XHTML6F\Chapter09\Solutions\InTheLab\lab9-1solutions.html");
    	document.write("St. Michael's Hospital");
    	document.write("This document was last modified "+day+"/"+month+"/"+year);
    }
    
    </script>
    <style type="text/css">
    hr {
    	color:#006633;
    	width:600px;
    	height: 5px;
    	}
    	
    .center {
    	text-align:center;
        }
    
    table {
    	margin-left:15%;
    	margin-right:15%;
        }
    .cell-width {
    	width: 50%;
    }
    	
    .left-align {
       width: 50%;
       left: 0;
       }
    
    .right-align {
       width: 50%;
       right: 0;
       text-align: right; 
       } 
      
    </style>
    </head>
    <body onload="scrollColor(); copyRight();">
    <div class="center">
    <p><img src="lab9-1banner.jpg" alt="oakwood banner" width="750" height="120" /></p>
    <p style="font-family:Arial, Helvetica, sans-serif; font-size:16pt; font-weight:bold;">St. Michael's  Health Care Fair</p>
    <img src="hrimg-red.gif" width="750" height="5" alt="divider" />
    <div align="center">
    <p style="font-family:Arial, Helvetica, sans-serif; font-size:14pt; font-weight:bold; color: #aa0000">Please offer to donate blood during the Health Care Fair</p>
    </div>
    <img src="hrimg-red.gif" width="750" height="5" alt="divider" /> </div>
    <table>
      <tr>
        <td colspan="2">
        <p style="font-weight:bold; font-family:Arial, sans-serif; font-size:12pt">St. Micheal's Hospital</p>
        <p style="font-family: 'Times New Roman', Times, serif; font-size:12pt">St. Michael's Hospital is located in Northern Minnesota. St. Micheal's was created over 80 years ago as a research and teaching institution as part of the Lake Superior University Medical school. Today, St. Michael's Hospital's goal is to be on the forefront of medical research and technology, to provide future leaders in medical practice and research, and to be a leader in diagnosing and treating unique deseases. </p>
        </td>
      </tr>
      <tr>
        <td colspan="2">
        <p style="font-weight:bold; font-family:Arial, sans-serif; font-size:12pt">Mission</p>
    <p style="font-family: 'Times New Roman', Times, serif; font-size:12pt">Our mission is to provide the highest quality care to every one of our patients. St. Michael's Hospital is committed to bringing health and wellness to the greater community at large..</p>
        </td>
      </tr>
      <tr>
        <td colspan="2">
        <p style="font-weight:bold; font-family:Arial, sans-serif; font-size:12pt">Fall Health Care Fair</p>
        <p> The Health Fair runs from October 23rd to October 26th from 11 a.m. to 9 p.m. daily. Great Lakes Insurance is a proud sponsor of the 5th annual St. Michael's Health Fair. Area hospitals, clinics, and other health care providers will have health and wellness booths, entertainment, live music, free health screenings and live demonstrations     </p></td>
      </tr>
      <tr>
        <td class="right-align"><img src="lab9-1photo1.jpg" alt="school" width="235" height="270" /></td>
        <td class="left-align">
              <img src="lab9-1photo2.jpg" alt="school" width="180" height="270" />
        </td>
      </tr>
        <tr>
        <td colspan="2">
        <form id="announceMenu" action=" ">
          <p style="font-weight:bolder">
           Select an item from the list to see other current announcements:
             <select onchange="loadInfo();" name="Menu">
               <option>Select an information item</option>
               <option value="lab9-1entertainment">Entertainment</option>
               <option value="lab9-1exhibitors">Exhibitor Information</option>
             </select>
          </p>
        </form></td>
      </tr>
      <tr>
        <td colspan="2">
        <p style="font-weight:bold; font-family:Arial, sans-serif; font-size:12pt">For more information call <span style="font-family: 'Times New Roman', Times, serif; font-size:12pt"> 555-515-6500.</span>
        </p>    
        </td>
      </tr>
    </table>
    <p></p>
    <div id="displayCopyRight"></div>
    </body>
    </html>
    I added the semi-colons as you suggested. No change.

  • #7
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Bump. Looking for some insight on the issue.

  • #8
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,461
    Thanks
    11
    Thanked 600 Times in 580 Posts
    Code:
    function loadInfo() {
    	window.location=announceMenu.elements.Menu.value;
    }
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •