• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 280
  • Last Modified:

HELP Please error

Hi,

this is driving me crazy.

I am getting an error that says

Message: 'document.RTEDemo.SubCat' is null or not an object
Line: 1034
Char: 1
Code: 0

I cannot find why I am getting this error I do have SubCat field!!!!

here's my code.

Thank you

<script language="Javascript">  
 function setOptions(chosen) {
var selbox = document.RTEDemo.SubCat;
 var getmySubCat = '3, 2, <h1>Churches Bulletin <br>Chat Room</h1>,6, 5, Accounting/Finance,2, 1, Activities,6, 85, Admin,7, 164, Advertising,7, 165, Animal Care,2, 158, Announcements,4, 233, Antiques,5, 208, Apartment Rentals,4, 234, Appliances,6, 86, Architect,6, 87, Art,2, 27, Artists,4, 235, Arts/Crafts,4, 236, Auto Parts,7, 166, Automotive,7, 169, Baby Sitting,4, 237, Barter,7, 167, Beauty & Salon,4, 238, Beauty/Health Care,4, 239, Bikes,6, 88, Biotech,4, 240, Boats,4, 241, Books,5, 209, Building Lot,4, 242, Business,6, 89, Business,7, 168, Car Dealers,4, 243, Cars/Trucks,7, 170, Catering,4, 244, CDS/DVD/VHS,4, 245, Cell Phones,2, 28, Childcare,2, 39, Classes,7, 171, Cleaning,4, 246, Clothes/Acc,5, 211, Co-op Unit,4, 247, Collectibles,7, 172, Colledge Activities,2, 159, College Age,4, 248, Computer,5, 210, Condominium Unit,7, 173, Construction,7, 174, Cook,6, 90, Craft,7, 175, Creative,6, 91, Customer service,6, 92, Design,5, 212, Duplex,6, 93, Editing,6, 94, Education,7, 176, Education,2, 269, Elderly,7, 177, Elderly Activities,7, 178, Elderly Care,7, 179, Electrician,4, 249, Electronics,6, 95, Engineering,7, 180, Erotic,2, 32, Events,5, 213, Farm,4, 250, Farm/Garden,7, 181, Farm/Garden,7, 182, Fast Food,6, 96, Film,7, 183, Financial,6, 97, Fitness,6, 98, Food,4, 251, Free,7, 184, Free fast food delivery,2, 155, Free Stuff,4, 252, Furniture,4, 253, Garage Sale,2, 29, General,4, 254, General,2, 157, General Entertainment,6, 99, General labor,6, 100, Government,2, 30, Groups,6, 101, Health,7, 185, Health & Wellness,7, 186, Home,5, 214, Home Rentals,6, 102, Hospital,4, 255, Household,7, 187, Household,5, 215, Housing swap,6, 103, Human resources,7, 188, Insurance,6, 104, Internet engineers,2, 156, Items Wanted,4, 256, Jewelry,2, 268, Kids,7, 189, Kids Activities,7, 190, Labor,7, 191, Lawn & Garden,7, 192, Legal,6, 105, Legal,7, 193, Lessons,2, 35, Local news,2, 33, Lost & Found,6, 109, Management,6, 106, Manufacturing,6, 107, Marketing,4, 257, Materials,6, 108, Media,2, 160, Men,5, 216, Mobile/Manufactured Home,4, 258, Motorcycles,7, 194, Moving & Storage,5, 217, Multi-Family Home,4, 259, Music Instr,2, 34, Musicians,6, 110, Network,5, 218, New Construction,6, 111, Nonprofit sector,7, 195, Office,6, 112, Office,5, 219, Offie/Commercial,5, 220, Other Real Estate,7, 196, Paint,6, 114, Paralegal,5, 221, Parking/Storage,7, 197, Pet,2, 31, Pets,4, 260, Photo/Video,7, 198, Plummer,2, 36, Politics,2, 153, Preschoolers,5, 222, Raw Land,7, 199, Real Estate,6, 115, Real Estate,7, 200, Rental,7, 271, Restaurant,6, 116, Retail,5, 223, Room Wanted,5, 224, Roommates,5, 225, Rooms/Shared,5, 226, Row House,4, 261, RVS,6, 117, Sales,6, 118, Salon,6, 119, Science,6, 120, Security,5, 227, Single Family Home,6, 121, Skilled trade,7, 201, Skill`d trade,6, 122, Software,4, 262, Sporting,7, 202, Sports,5, 228, Sublets/Temporary,6, 123, Technical support,2, 161, The Gathering Place,4, 263, Tickets,5, 229, Time Share,4, 264, Tools,5, 230, Townhouse/Townhome,4, 265, Toys/Games,7, 203, Training & Education,6, 124, Transport,7, 204, Travel,6, 125, Tv,5, 231, Vacation Rentals,5, 232, Vacation swap,6, 126, Video,4, 266, Video Gaming,2, 38, Volunteers,4, 267, Wanted,6, 127, Web design,7, 205, Web Design & Tech,7, 206, Wedding & Photography,2, 154, Weekly Information,6, 128, Wholesale,2, 152, Women,7, 207, Writer,6, 129, Writing';
 
   var CTDataList = getmySubCat.split(",");
 
   selbox.options.length = 0;
   if (chosen == " ") {
   selbox.options[selbox.options.length] = new Option('Please select a category',' ');
   }
 
   for(var i=0, limit=CTDataList.length; i<limit; i+=3)  
if (chosen == CTDataList[i]) {
  selbox.options[selbox.options.length] = new
Option(CTDataList[i+2],CTDataList[i+1]);
}
}

</script> 


_____________________________________________

  <select name="MainCat" width="230" style="width: 230px" size="1"
 onChange="setOptions(this.options[this.selectedIndex].value);">
                                              <option value=" " selected="selected"> </option>
                                              
                                                <option value="2">Community</option>
                                              
                                                <option value="4">For Sale</option>
                                              
                                                <option value="6">Jobs</option>
                                              
                                                <option value="5">Real Estate</option>
                                              
                                                <option value="7">Services</option>
                                              
                                            </select>
        


___________________________________________________

  <select name="SubCat" size="1" width="230" style="width: 230px">
                                              <option value=" " selected="selected"> </option>
                                              <option></option>
                                            </select>

Open in new window

0
lulu50
Asked:
lulu50
  • 3
  • 2
  • 2
  • +1
2 Solutions
 
EyalCommented:
add id attribute to the select tags
0
 
lulu50Author Commented:
Eyal

like this

 <select name="SubCat" size="1" id="SubCat" width="230" style="width: 230px">

I still have the error

0
 
ansudhindraCommented:
check the form name you have given. Form name should be "RTEDemo" (javascript is case sensitive).
Or
you can try giving an id attribute to the select box "SubCat",.. say id='subCatSel'..
and replace the line number 3 with the below code..

var selbox = document.getElementById('subCatSel');
0
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.

 
lulu50Author Commented:
how can i say in javascript if

document.getElementById('SubCat'); is not defined than use
 document.RTEDemo.SubCat;


 var selbox = document.getElementById('SubCat');
var selbox = document.RTEDemo.SubCat;

0
 
chaitu chaituCommented:
use document.forms[0].SubCat
0
 
chaitu chaituCommented:
if(document.getElementById('SubCat'))
document.forms[0].SubCat
or
var selbox = document.getElementById('SubCat');
0
 
EyalCommented:
using  document.RTEDemo.SubCat; is very bad practice.

var selbox = document.getElementById('SubCat');
if (selbox == null)
selbox = document.RTEDemo.SubCat;

0
 
lulu50Author Commented:
Thank you
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now