Solved

error message on page load

Posted on 2004-04-02
11
825 Views
Last Modified: 2007-12-19
Hi,

I have this code, which produces an error message when loaded in the browser (IE6): "Object expected". Typically I would look for a missing semicolon or opening/closing bracket or something like that in the case of such error message, but this time I cannot find such a problem.

Anyone with better eyes than me who can find what is the problem here? Please note that the code is in development and so does not do very much meaningful at this point.

When finished, it will fill a select dropbox with select items from the XML data island, depending on limits chosen in selects "selPrisFra" and "selPrisTil" (select Price From, and select Price To, respectively).

The objective is to download a set of data from the server once, and then get the different sets of options in two dropboxes depending on the selected value in two other (static) dropboxes and the selected value of one of the two dynamic dropboxes... Thus avoiding to use session vars and reload, with overhead on server due to DB access.

See code below.


Kind regards,
Tavseth


<html><head><title>SomeTitle</title>
<style type="text/css"><!--
 [STYLE DEFS] -->
</style>
<script type="text/javascript" language="JavaScript">
<!--
 [FUNCTIONS THAT WORK FINE]

// ---------------------functions that cause error below here---------------------
function fnDeleteItems(objSelect)
{
  var objSel = document.forms[0].elements[objSelect];
  for (i=objSel.length; i>0; i--)
  {
    objSel.options[i]=null;
  }
}

function fnAddItem(objSelect, strValue, strText, strClass)
{
  var ObjSel = document.forms[0].elements[objSelect];
  intLength = objSel.length;
  objSel.options[intLength] = new Option;
  objSel.options[intLength].value = strValue;
  objSel.options[intLength].text = strText;
  objSel.options[intLength].class = strClass;
}

function fnLoadOmrader()
{
  fnDeleteItems('selOmrade');

  var taden = document.forms[0].elements('selPrisFra');
  var iFraHusleie = taden.options[taden.selectedIndex].value;

  var taden = document.forms[0].elements('selPrisTil');
  var iTilHusleie = taden.options[taden.selectedIndex].value;

  var intCount;
 
  for(intCount=0; intCount<10; intCount++)
  {
    if ((iFraHusleie <= 5000) && (iTilHusleie >= 5000))
    {
      fnAddItem('selOmrade', '0301', 'Oslo', 'kommune');
    }
   
  }
}
// ---------------------functions that cause error above here---------------------
// -->
</script>
</head>
<body>
 [XML DATA ISLAND HERE]
 [HTML STUFF INCLUDING FORM1 W/SELECT DROPBOXES HERE]
</body>
</html>
0
Comment
Question by:tavseth
  • 3
  • 3
  • 2
  • +2
11 Comments
 
LVL 10

Expert Comment

by:Havin_it
ID: 10740383
Haven't spotted anything yet (my eyes ain't great either!) but the IE error dialogue should tell you which line the error occurs on; that might speed things up a bit.
0
 

Author Comment

by:tavseth
ID: 10740466
Well, i did try that and it pretty much puts me at the </script> tag. And I am still confused, because I've counted my brackets and feel pretty sure I should be allowed to run into the closing tag at that point...

rgds, tavseth
0
 
LVL 17

Expert Comment

by:mreuring
ID: 10740708
Well, I'm not sure if Javascript is lenient enough to allow this line:
 objSel.options[intLength] = new Option;
However according to proper syntaxing it oughta be:
 objSel.options[intLength] = new Option();

Good lukc,

 Martin
0
 
LVL 25

Assisted Solution

by:devic
devic earned 300 total points
ID: 10742455
try to change :
 objSel.options[intLength].class = strClass;

to:
 objSel.options[intLength].className = strClass;
0
 

Author Comment

by:tavseth
ID: 10756126
Alright... javascript is not my forte, plus it is a challenge to troubleshoot, but i've made some way with these problems.

devic, you're right the correct way is to use "classname" in stead of "class". In addition to this I had messed with exchanging the && in the IF-statement with AND (fnLoadOmrader), which evidently did not work. Being that the AND was not presented in my question, there was no way for you all to detect that. But it explains why I have spent extra time troubleshooting... ;)

Now I have made the fnDeleteItems work fine, and my fetching of data from the data island (see code below, where it IF statement is changed to check values from the data island in stead of test run constants) is working fine.

HOWEVER, I have a problem in the fnLoadOmrader where the object objSel is not defined when I reach the line with "intLength = objSel.Length". Please recall I have just deleted all but one options in the 'selOmrade' select list, but still I would expect the object objSel to be defined (the equivalent construct works just fine in fnDeleteItems...)

So I have to ask you all again -- what is the next step in this quest for running code?

Rgds, tavseth



function fnDeleteItems(objSelect)
{
  var objSel = document.forms[0].elements[objSelect];
  for (i=objSel.length; i>0; i--)
  {
    objSel.options[i]=null;
  }
}

function fnAddItem(objSelect, strValue, strText, strClass)
{
  var ObjSel = document.forms[0].elements[objSelect];
  intLength = objSel.length;
  objSel.options[intLength] = new Option();
  objSel.options[intLength].value = strValue;
  objSel.options[intLength].text = strText;
  objSel.options[intLength].classname = strClass;


}

function fnLoadOmrader()
{
  fnDeleteItems('selOmrade');

  var taden = document.forms[0].elements('selPrisFra');
  var iFraHusleie = taden.options[taden.selectedIndex].value;

  var taden = document.forms[0].elements('selPrisTil');
  var iTilHusleie = taden.options[taden.selectedIndex].value;

  var intCount;
 
  for(intCount=0; intCount<data.recordset.recordcount; intCount++)
  {
    if ((iFraHusleie <= data.recordset("husleie").value) && (iTilHusleie >= data.recordset("husleie").value))
    {
      fnAddItem('selOmrade', data.recordset("knr").value, data.recordset("kommune").value, 'omrade2');
    }
   
  }
}
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 17

Accepted Solution

by:
mreuring earned 200 total points
ID: 10756458
Javascript is still casesensitive :)
  var ObjSel = document.forms[0].elements[objSelect];
  intLength = objSel.length;
unless mistaken should read:
  var objSel = document.forms[0].elements[objSelect]; // <<< the variable was written with capital O
  intLength = objSel.length;

greets,

 Martin
0
 
LVL 25

Assisted Solution

by:devic
devic earned 300 total points
ID: 10761133
and classname must be className
0
 
LVL 1

Expert Comment

by:i_rajeevsingh
ID: 10897997
function fnAddItem(objSelect, strValue, strText, strClass)
{
  var ObjSel = document.forms[0].elements[objSelect];  <-----------   'O' here should be small o
  intLength = objSel.length;
  objSel.options[intLength] = new Option;
  objSel.options[intLength].value = strValue;
  objSel.options[intLength].text = strText;
  objSel.options[intLength].class = strClass;
}


Regards
Rajeev
0
 
LVL 1

Expert Comment

by:i_rajeevsingh
ID: 10898473
mreuring
Well never seen ur response
0
 
LVL 1

Expert Comment

by:i_rajeevsingh
ID: 10898475
mreuring
Well not seen ur response
0
 

Author Comment

by:tavseth
ID: 10898976
The solution is now working excellent. Sorry about the long delay before closing, been on vacation and forgot about the whole thing after coming back...

I now have a working system where I load data from an XML island, and have dynamic loading of SELECT drop boxes depending on values of other drop boxes:

First SELECT: Low boundry of price
Second SELECT: Hogh boundry of price
Third SELECT: Fill with geographical entities for which houses for rent fit between Low and High price, upon change of SELECTS 1 and 2.
Fourth SELECT: Fill with addresses for houses which are within price limits (SELECT 1 and 2) AND are located within geographical area as specified by SELECT 3, upon change of either of SELECTs 1, 2, or 3.

Benefit of this solution is that I don't have to run SQL DB access for each change of SELECTs 1, 2, or 3, all in all I only have to load the page once. Used this for an interactive ad for our real estate company. It gives extremely improved performance on our server, as the load on the SQL DB is reduced to nil.

Drawback of this solution (as I have it now) is that it is only working for IE. Did not work properly for Opera, no other browser tested. Another drawback is that I have to mine the XML data at regular intervals, hence the XML data will only be as current as my last mining. Finally, the in-browser performance of this solution is a bit slower than before, but the user still waits less time for the changes of the SELECTs than he/She would have to wait for an SQL DB access and page reload.

I have not prioritized testing and refining of solution for other platforms, as cost of development currently too high.

Although not quite on topic I include the code here for the benefit of droppers-by.

Norwegian/english dictionary:
  selPrisFra = selPriceFrom
  selPrisTil = selPriceTo
  selOmrade = selArea
  selBoliger = selDwellings
  taden = grabthis (just a local var)
  iFraHusleie = iFromRent
  iTilHusleie = iToRent
  kommune = municipal
  Knr = Municipal Code (number identifying each municipal in the country)
  bydel = City Part/division -- geographical and administrative; used in Oslo, Norway
  kr/mnd = currency NOK per month


===========================================================================
<%@LANGUAGE="VBSCRIPT"%>
<html>
<head>
<title>Whatchamacallit</title>
<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
<!--
function fnSetWidths()
{
  document.form1.selPrisFra.style.width = 100;
  document.form1.selPrisTil.style.width = 100;
  document.form1.selOmrade.style.width = 150;
  document.form1.selBoliger.style.width = 150;
}

function ShowValueOmrade()
{
  alert(document.form1.selOmrade.value);
}

function fnDeleteItems(objSelect)
{
  var objSel = document.forms[0].elements[objSelect];
  for (i=objSel.length; i>0; i--)
  {
    objSel.options[i]=null;
  }
}

function fnAddItem(objSelect, strValue, strText, strClass)
{
  var objSel = document.forms[0].elements[objSelect];
  intLength = objSel.length;
  objSel.options[intLength] = new Option();
  objSel.options[intLength].value = strValue;
  objSel.options[intLength].text = strText;
  objSel.options[intLength].className = strClass;


}

function fnLoadOmrader()
{
  fnDeleteItems('selOmrade');

  var taden = document.forms[0].elements('selPrisFra');
  var iFraHusleie = taden.options[taden.selectedIndex].value;

  var taden = document.forms[0].elements('selPrisTil');
  var iTilHusleie = taden.options[taden.selectedIndex].value;

  var intCount;

  data.recordset.moveFirst();  

  while (data.recordset.absoluteposition < data.recordset.recordcount)
  {
    if ( ( (iFraHusleie - data.recordset("husleie").value) <= 0 ) && ( (iTilHusleie - data.recordset("husleie").value) >= 0 ) )
    {
      var thisKommune = data.recordset("kommune").value;
      var thisKnr = data.recordset("knr").value;
      var Kcount = 0;
      if (thisKnr == '0301')
      {
        var arrBydel = new Array();
        var arrBcount = new Array();
        arrBydel[arrBydel.length] = data.recordset("bydel").value;
        arrBcount[arrBcount.length] = 0;
        while ((thisKnr == data.recordset("knr").value) && (data.recordset.absoluteposition < data.recordset.recordcount))
        {
          if ( ( (iFraHusleie - data.recordset("husleie").value) <= 0 ) && ( (iTilHusleie - data.recordset("husleie").value) >= 0 ) )
          {
            Kcount++;
            if (arrBydel[arrBydel.length-1] == data.recordset("bydel").value)
            {
              arrBcount[arrBcount.length-1]++;
            }
            else
            {
              arrBydel[arrBydel.length] = data.recordset("bydel").value;
              arrBcount[arrBcount.length] = 1;
            }
          }
          data.recordset.moveNext();
        }
        var tmpS = thisKommune.toUpperCase() + ' (' + Kcount + ')';
        fnAddItem('selOmrade', thisKnr, tmpS , 'kommune');

        for (i=0; i < arrBydel.length; i++)
        {
          var tmpS = '- ' + arrBydel[i] + ' (' + arrBcount[i] + ')';
          fnAddItem('selOmrade', arrBydel[i], tmpS , 'bydel');
        }
      }
      else
      {
        var arrOmrade = new Array();
        var arrOcount = new Array();
        arrOmrade[arrOmrade.length] = data.recordset("omrade").value;
        arrOcount[arrOcount.length] = 0;
        while ((thisKnr == data.recordset("knr").value) && (data.recordset.absoluteposition < data.recordset.recordcount))
        {
          if ( ( (iFraHusleie - data.recordset("husleie").value) <= 0 ) && ( (iTilHusleie - data.recordset("husleie").value) >= 0 ) )
          {
            Kcount++;
            if (arrOmrade[arrOmrade.length-1] == data.recordset("omrade").value)
            {
              arrOcount[arrOcount.length-1]++;
            }
            else
            {
              arrOmrade[arrOmrade.length] = data.recordset("Omrade").value;
              arrOcount[arrOcount.length] = 1;
            }
          }
          data.recordset.moveNext();
        }
        var tmpS = thisKommune.toUpperCase() + ' (' + Kcount + ')';
        fnAddItem('selOmrade', thisKnr, tmpS , 'kommune');

        for (i=0; i < arrOmrade.length; i++)
        {
          var tmpS = '- ' + arrOmrade[i] + ' (' + arrOcount[i] + ')';
          fnAddItem('selOmrade', arrOmrade[i], tmpS , 'omrade');
        }
      }
    }
    else
    {
      data.recordset.moveNext();
    }
  }
  data.recordset.moveFirst();
}

function fnLoadBoliger()
{
  fnDeleteItems('selBoliger');

  var Ofilter = 0;

  if (document.form1.selOmrade.selectedIndex > 0)  
  {
    Ofilter = 1;
  }

    var taden = document.form1.selPrisFra;
    var iFraHusleie = taden.options[taden.selectedIndex].value;

    var taden = document.form1.selPrisTil;
    var iTilHusleie = taden.options[taden.selectedIndex].value;

    var taden = document.form1.selOmrade;
    var Otype = taden.options[taden.selectedIndex].className;
    var Otxt = taden.options[taden.selectedIndex].value;

   

    var intCount = 0;

    data.recordset.moveFirst();

    while (data.recordset.absoluteposition < data.recordset.recordcount)
    {
      if ( ((iFraHusleie-data.recordset("husleie").value) <= 0) && ((iTilHusleie-data.recordset("husleie").value) >= 0) )
      {

        if ((Ofilter == 0) || ( (Otype == 'kommune') && (data.recordset("knr").value == Otxt) ) || ( (Otype == 'omrade') && (data.recordset("omrade").value == Otxt) ) || ( (Otype == 'bydel') && (data.recordset("bydel").value == Otxt) ) )
        {

          intCount++;
          tmpS = data.recordset("adresse").value + ' (' + data.recordset("husleie").value + ' kr)';
          fnAddItem('selBoliger', data.recordset("onr").value, tmpS, 'bolig');
        }
      }
      data.recordset.moveNext();
    }
    data.recordset.moveFirst();

    var taden = document.form1.selBoliger;
    tmpS = '<fant ' + intCount + ' ledige boliger>';
    taden.options[0].text = tmpS;
   

}

// -->
</SCRIPT>


</head>
<body bgcolor="white" text="#FFFFFF" link="#FFFF00" vlink="#FFFF00" alink="#FFFF00" leftmargin="10" topmargin="12" onload="fnSetWidths();fnLoadOmrader();fnLoadBoliger()">

<xml id="data" src="finn.xml"></xml>

<DIV id=Layer1
style="Z-INDEX: 1; LEFT: 0px; WIDTH: 360px; POSITION: absolute; TOP: 0px; HEIGHT: 60px">
<img src="bann01042004.gif" border="0">
</div>

<div style="Z-INDEX: 2; LEFT: 10px; WIDTH: 722px; POSITION: absolute; TOP: 17px; HEIGHT: 60px" align="right"><form id="form1" name="form1" method="post" action="">
<table border="0">
<tr>
<td align="right">Pris fra:&nbsp;<select name="selPrisFra" onChange="fnLoadOmrader();fnLoadBoliger()">
    <option class="prisfra" value="0" selected>&lt;4.000 kr/mnd</option>
    <option class="prisfra" value="4000">4.000 kr/mnd</option>
    <option class="prisfra" value="5000">5.000 kr/mnd</option>
(...)
    <option class="prisfra" value="21000">21.000 kr/mnd</option>
    <option class="prisfra" value="22000">22.000 kr/mnd</option>
    <option class="prisfra" value="23000">23.000 kr/mnd</option>
    <option class="prisfra" value="24000">24.000 kr/mnd</option>
  </select><br>
til:&nbsp;<select name="selPrisTil" onChange="fnLoadOmrader();fnLoadBoliger()">
    <option class="pristil" value="4000">4.000 kr/mnd</option>
    <option class="pristil" value="5000">5.000 kr/mnd</option>
    <option class="pristil" value="6000">6.000 kr/mnd</option>
(...)
    <option class="pristil" value="22000">22.000 kr/mnd</option>
    <option class="pristil" value="23000">23.000 kr/mnd</option>
    <option class="pristil" value="24000">24.000 kr/mnd</option>
    <option class="pristil" value="999999" selected>&gt;24.000 kr/mnd</option>
  </select></td>
<td align="right">Omr&aring;de:&nbsp;<select name="selOmrade" onChange="fnLoadBoliger();">
      <option class="omrade" value="">&lt;Alle omr&aring;der&gt;</option>
      


  </select><br>
Boliger:&nbsp;<select name="selBoliger" onchange="if (this.options[this.selectedIndex].value!='-1'){MyWindow=window.open('http://[SOME_URL]?onr='+this.options[this.selectedIndex].value,'MyWindow','toolbar=yes,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=780,height=580,left=10,top=10');MyWindow.focus()} ">
    <option class="bolig" value="-1">&lt;...henter info&gt;</option>
  </select></td></tr></table>
</form></div>
</body>
</html>
===========================================================================
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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 the basics of jQuery including how to code hide show and toggles. 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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now