Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Error trying to load javascript function using onload="MyFunction()"

Posted on 2011-04-28
7
Medium Priority
?
281 Views
Last Modified: 2012-05-11
Hi,

Can't figure out why I keep getting an error while trying to execute this line:

<body onload = "LoadArray()">

The error is:   Microsoft JScript runtime error: Object expected

I delcare the file in the header like this:

<head>
    <title></title>
    <script type="text/javascript" src="ArrayFile.js">

The entire HTML is in the snippet below.

Thanks



<html>
<head>
    <title></title>
    <script type="text/javascript" src="ArrayFile.js"">
</script>
</head>
<body onload = "LoadArray()"> 

<form method="post" action="#">
<p>
  <label>Select Options: 
  <select id="myoptions" name="myoptions">
</select></label>
<label>Select Sub Options: 
<select id="subOptions" name="subOptions">
</select></label></p>
</form>
</body>
</html>

Open in new window

0
Comment
Question by:John500
7 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 35488290
check the case of the function inside ArrayFile.js

loadArray

loadarray

LOadArray
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35488504
If you include the javascript in that HTML file instead of just linking it, you will probably get the same error.  That error normally means that you have tried to use something that isn't defined when it is first encountered.
0
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 35489430
Remove the browser's cache and try again, and see if it's fixed?

alternatively, post the code in ArrayFile.js, so that we know what you're trying to do.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35489508
Can you paste your js file ..
0
 

Author Comment

by:John500
ID: 35490257
The js file contents is in the snippet below.  Between this and my first post, all the code is available.  Thanks !
function LoadArray() {
    var options=new Array();
    options[0]=new Array();
    options[0]['myoptions']='Option_1';
    options[0]['sub_options']=['html_link_1','html_link_2','html_link_3','html_link_4'];
    options[1]=new Array();
    options[1]['myoptions']='Option_2';
    options[1]['sub_options']=['html_link_5','html_link_6','html_link_7','html_link_8'];
    function initBoxes(box1,box2) {
    var myoptions=document.getElementById(box1);
    var subOptions=document.getElementById(box2);
    for (i=0; i<options.length; i++) {
      var x=document.createElement('option');
      var y=document.createTextNode(options[i]['myoptions']);
      if (window.attachEvent) { // for IE
      x.setAttribute('value',y.nodeValue);
      }
      x.appendChild(y);
      myoptions.appendChild(x);
    }

    myoptions.onchange=function() {
      if(this.value!="") {
       var list=document.getElementById(box2);
       while (list.childNodes[0]) {
        list.removeChild(list.childNodes[0])
       }
       fillBox2(subOptions,this.value);
       }
      }

    fillBox2(subOptions,myoptions.value);
}


function fillBox2(box2, myoptions) {
    for (i = 0; i < options.length; i++) {
        if (options[i]['myoptions'] == myoptions) {
            var sub_options = options[i]['sub_options'];
        }
    }
    for (i = 0; i < sub_options.length; i++) {
        var x = document.createElement('option');
        var y = document.createTextNode(sub_options[i]);
        x.appendChild(y);
        box2.appendChild(x);
    }
}

Open in new window

0
 
LVL 20

Accepted Solution

by:
Sathish David  Kumar N earned 2000 total points
ID: 35490417
Your not closing LoadArray();

  options[1]['sub_options']=['html_link_5','html_link_6','html_link_7','html_link_8'];

}-----------> this is requried
    function initBoxes(box1,box2) {

0
 

Author Closing Comment

by:John500
ID: 35497937
Thanks!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question