codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  is null or not an object error  andybeh at 22:14 on Wednesday, July 05, 2006
 

Hi All,

I'm pretty much a novice at javascript and have a hit a roadblock with a piece of code. I have a form which automatically adds new fields when the user tabs off of a certain field. This part of the code works fine, however when I try to set the options for a newly created 'select' box, I receive an error that the form element is null or not an object. As you can see in the code below, I have tried debugging the code by alerting all of the form values to screen. The name of the newly created 'select' element appears so to my understanding it is now a valid form element. I have also tried checking to see if it is a
null value and it skips through this check which indicates to me that it is neither a null value nor an invalid object. So can anyone see anything glaringly obvious in the code below (apart from the fact that it probably isn't the tidiest code ever written)?


<SCRIPT LANGUAGE="JavaScript">
<!--
function createResource(val)
{
var departmentVal = val.value;
var lineID = document.updateCar.elements ["form_count"].value;
var resourceID = 'frmResource' + lineID;
var objOption = document.createElement("option");
var cnt;
cnt = 0;
for(var i=0;i<document.updateCar.elements.length;i++)
{
// alert(document.updateCar.elements.name + ' **' +
document.updateCar.elements.value + '**');
}
//alert(document.updateCar.elements["frmResource" + lineID].value);
if (document.updateCar.elements["frmResource" + lineID] == '')
{
alert('the value is null');
}
document.updateCar.elements["frmResource" +
lineID].options[cnt]=new Option('Select A Resource', 'X', false,
false);
document.updateCar.elements["frmResource" +
lineID].options.length=0
}
//-->
</script>

The line that errors out is:

if (document.updateCar.elements["frmResource" + lineID] == '')

Cheers

ab

  Re: is null or not an object error  amery buck at 06:02 on Monday, April 05, 2010
 

Beautiful blog with great informational content. Mostly certifications related and not an object error related topics are really very good. <a href="http://www.latest-testking.com/microsoft-70-291.html">testking 70-291</a>, <a href="http://www.latest-testking.com/microsoft-70-293.html">testking 70-293</a> and <a href="http://www.latest-testking.com/microsoft-70-431.html">testking 70-431</a> are also good topics. Thanks for this great sharing.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Trying to make backcolor change after I enter values
•  Re: Difference between two dates including From & To date
•  Disabe onbeforeunload event?
•  Re: MS Access connection in JSP
•  Re: execute linux commands in perl script
•  Re: Server Name or Address could not be resolved?
•  Re: is null or not an object error
•  Re: Using Crystal Reports for generating dynamic reports in JAVA
•  Re: how to connect asp.net to sql server 2000


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010