JS Code error ...help

Hi all,I posted a question yesterday and still experiencing a problem. I have a DialogList field named “POType” with that should change the value of several other DialogList type of fields when its value changes but the fields go blank instead of getting the value “-Not Applicable-”. Each of these fields has the required value in its list (“-Not Applicable-“) in second position.

I get an error message (in IE7) as follows:

Error: ‘type’ is null or not an object

Here is the onChange event code for the POType field:

var doc = document.forms[0];

CustomerField = doc.Customer;

Value=“-Not Applicable-”;

function selectCustomer(CustomerField, Value) {

var selField = doc.elements[Customer];

if (selField.type.indexOf(“select”)>-1) {

var opts = selField.options;

for (var i=0; i<opts.length; i++) {

if (opts[i].text == Value || opts[i].value == Value) {

opts[i].selected;

break;

}

}

}

else if (selField.type == “hidden”) {

selField.value = Value;

}

}

field=“OrderType”;

nl=“\n”;

OrderTypeval=doc.elements[field].options[doc.elements[field].selectedIndex].text;

if (OrderTypeval==“Stock Order”){

vCustomer=selectCustomer();

vCustomerContact=doc.elements[CustomerContact].options[1].selected;

vAccountManager=doc.elements[AccountManager].options[1].selected;

vProjectManager=doc.elements[ProjectManager].options[1].selected;

vTechLead=doc.elements[TechLead].options[1].selected;

doc.Customer.value=vCustomer;

doc.CustomerContact.value=vCustomerContact;

doc.AccountManager.value=vAccountManager;

doc.ProjectManager.value=vProjectManager;

doc.TechLead.value=vTechLead;

}  

doc.Customer.focus();

Can you tell me how I can fix this so that it can work?

Thanks,

Dan

Subject: JS Code error …help

Oops – my fault, Dan. Everywhere you’re setting a selected option, add “= true” at the end of “.options.selected”.

Subject: RE: JS Code error …help

Hi Stan,

I get an error message (in IE7) as follows:

Error: ‘elements[…].options’ is null or not an object

Here is the onChange event code for the POType field as corrected:

var doc = document.forms[0];

CustomerField = doc.Customer;

Value=“-Not Applicable-”;

function selectCustomer(CustomerField, Value) {

var selField = doc.elements[Customer];

if (selField.type.indexOf(“select”)>-1) {

var opts = selField.options;

for (var i=0; i<opts.length; i++) {

if (opts[i].text == Value || opts[i].value == Value) {

opts[i].selected = tue;

break;

}

}

}

else if (selField.type == “hidden”) {

selField.value = Value;

}

}

field=“OrderType”;

nl=“\n”;

OrderTypeval=doc.elements[field].options[doc.elements[field].selectedIndex].text;

if (OrderTypeval==“Stock Order”){

//====HERE IS THE PROBLEM LINE===========

vCustomer=doc.elements[Customer].options[1].selected = tue;

//=================================

vCustomerContact=doc.elements[CustomerContact].options[1].selected = tue;

vAccountManager=doc.elements[AccountManager].options[1].selected = tue;

vProjectManager=doc.elements[ProjectManager].options[1].selected = tue;

vTechLead=doc.elements[TechLead].options[1].selected = tue;

doc.Customer.value=vCustomer;

doc.CustomerContact.value=vCustomerContact;

doc.AccountManager.value=vAccountManager;

doc.ProjectManager.value=vProjectManager;

doc.TechLead.value=vTechLead;

}

doc.Customer.focus();

Thanks,

Dan

Subject: RE: JS Code error …help

The fieldnames in elements are strings – they need to be quoted if they’re not variables.