document null or not an object

E

elmobeh

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>

Cheers

ab
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top