hcl-bot
December 13, 2007, 3:37pm
1
Hi all,I have a DialogList field named “POType” with that should change the value of other DialogList type of fields when its value chjanges but the fields go blank instead of getting the value “-Not Applicable-”. Each of these fields has that value in its list. Can someone tell me how this can work?
Here is the onChange event code for the POType field:
field=“OrderType”;
nl=“\n”;
OrderTypeval=document.forms[0].elements[field].options[document.forms[0].elements[field].selectedIndex].text;
if (OrderTypeval==“Stock Order”){
vCustomer="-Not Applicable-";
vCustomerContact="-Not Applicable-";
vAccountManager="-Not Applicable-";
vProjectManager="-Not Applicable-";
vTechLead="-Not Applicable-";
document.forms[0].Customer.value=vCustomer;
document.forms[0].CustomerContact.value=vCustomerContact;
document.forms[0].AccountManager.value=vAccountManager;
document.forms[0].ProjectManager.value=vProjectManager;
document.forms[0].TechLead.value=vTechLead;
}
var f = document.forms[0];
f.Customer.focus();
Thanks,
Dan
hcl-bot
December 13, 2007, 9:56pm
2
Subject: JS code question - validation
The general form for setting the value of a is:
document.forms[0].elements[FieldName].options[index].selected;
If the position of “-Not Applicable-” in the list is known (either the first, second or last option), then it’s relatively straightforward. For the first, it would be:
document.forms[0].elements[FieldName].options[0].selected;
For the last, it would be:
document.forms[0].elements[FieldName].options[document.forms[0].elements[FieldName].options.length - 1].selected;
If the value you want is in an unknown position, then you have to loop through the options looking for the text:
function selectOption(fieldName, value) {
var selField = document.forms[0].elements[fieldName];
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;
}
}
hcl-bot
December 14, 2007, 8:39am
3
Subject: RE: JS code question - validation
Hi Stan,I updated my code to reflect the exact position of the value for each field targeted:
field=“OrderType”;
nl=“\n”;
var doc = document.forms[0];
OrderTypeval=doc.elements[field].options[doc.elements[field].selectedIndex].text;
if (OrderTypeval==“Stock Order”){
vCustomer=doc.elements[Customer].options[1].selected;
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();
I now get an error message (in IE7) as follows:
Error: ‘elements[…].options’ is null or not an object
Can you tell me how I can fix this so that it can work?
Thanks,
Dan