I have a CGI script that I've embedded a javascript in (to give me select boxes related to each other). I've been working on this for several days and have narrowed the problem down to the way the javascript works.
To see this script working go to:
<!-- m --><a class="postlink" href="http://avs-1.com/cgi-local/db3/db.cgi?db=demostruc&uid=demo.105059387870273&cap_add_form=1">http://avs-1.com/cgi-local/db3/db.cgi?d ... add_form=1</a><!-- m -->
The same script runs 3 times (it works with one exception)
First, it loads when you add a new record
then when you submit that record, the preview form
loads the script again so that the record can be edited if needed.
The third place the script loads is on the error page which allows you to fix your errors and resubmit the record, this doesn't cause a problem.
The problem is on the preview form.
In previewing the record, you see the data in text boxes as you submitted it
but it reloads the add form to allow you to make changes.
When this happens, the script tramples the values for the 2 select boxes with null values.
I need to get the select boxes to initialize with the submitted data (if selections were made on the add form).
OR
to save the data to a different variable and check it to see what value should be saved to the form.
THanks for any help! Below is the script code in question:
function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
var i, j;
var prompt;
// empty existing items
for (i = selectCtrl.options.length; i >= 0; i--) {
selectCtrl.options = null;
}
prompt = (itemArray != null) ? goodPrompt : badPrompt;
if (prompt == null) {
j = 0;
}
else {
selectCtrl.options[0] = new Option(prompt);
j = 1;
}
if (itemArray != null) {
// add new items
for (i = 0; i < itemArray.length; i++) {
selectCtrl.options[j] = new Option(itemArray[0]);
if (itemArray[1] != null) {
selectCtrl.options[j].value = itemArray[1];
}
j++;
}
// select first item (prompt) for sub list
selectCtrl.options[0].selected = true;
}
}
function init(frm) {
var combo = frm.Select_Box;
var combo2 = frm.Category;
frm.category.value = combo.options[combo.selectedIndex].value;
frm.occupancytype.value = combo2.options[combo2.selectedIndex].value;
}
To see this script working go to:
<!-- m --><a class="postlink" href="http://avs-1.com/cgi-local/db3/db.cgi?db=demostruc&uid=demo.105059387870273&cap_add_form=1">http://avs-1.com/cgi-local/db3/db.cgi?d ... add_form=1</a><!-- m -->
The same script runs 3 times (it works with one exception)
First, it loads when you add a new record
then when you submit that record, the preview form
loads the script again so that the record can be edited if needed.
The third place the script loads is on the error page which allows you to fix your errors and resubmit the record, this doesn't cause a problem.
The problem is on the preview form.
In previewing the record, you see the data in text boxes as you submitted it
but it reloads the add form to allow you to make changes.
When this happens, the script tramples the values for the 2 select boxes with null values.
I need to get the select boxes to initialize with the submitted data (if selections were made on the add form).
OR
to save the data to a different variable and check it to see what value should be saved to the form.
THanks for any help! Below is the script code in question:
function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
var i, j;
var prompt;
// empty existing items
for (i = selectCtrl.options.length; i >= 0; i--) {
selectCtrl.options = null;
}
prompt = (itemArray != null) ? goodPrompt : badPrompt;
if (prompt == null) {
j = 0;
}
else {
selectCtrl.options[0] = new Option(prompt);
j = 1;
}
if (itemArray != null) {
// add new items
for (i = 0; i < itemArray.length; i++) {
selectCtrl.options[j] = new Option(itemArray[0]);
if (itemArray[1] != null) {
selectCtrl.options[j].value = itemArray[1];
}
j++;
}
// select first item (prompt) for sub list
selectCtrl.options[0].selected = true;
}
}
function init(frm) {
var combo = frm.Select_Box;
var combo2 = frm.Category;
frm.category.value = combo.options[combo.selectedIndex].value;
frm.occupancytype.value = combo2.options[combo2.selectedIndex].value;
}