Click to See Complete Forum and Search --> : Browser Incompatabilities...


Matthew Perciva
04-26-2005, 08:34 PM
G'Day,

I've been writing some fairly basic JavaScripts revolving around selections from a combo box. They work perfectly fine for me (using Firefox), but others have told me they had some problems.

One of those problems is with a combo box which changes the contents of another combo box. The steps are to set the length to 1 (ie only leave the default option that is used by all) and add x new options. An example is below:

<!--
function updateSelection(FormData)
{
var selection = FormData.recipes.value;
if (selection == "gustRec")
{
FormData.name.value = "gustRec";
FormData.step.length = "1";
FormData.step.options[1] = new Option("gustRec_1", "gustRec_1");
FormData.step.options[2] = new Option("gustRec_2", "gustRec_2");
FormData.step.options[3] = new Option("gustRec_3", "gustRec_3");
FormData.oper.value = "No Step";
FormData.conf.value = "None Selected";
FormData.pipe.value = "";
FormData.size.value = "";
FormData.snum.value = "0";
FormData.dels.checked = false;
FormData.delr.checked = false;
}
}
// -->

On my system, this works fine, however a Mac user told me that if they, say, select one with seven options followed by another with three, then they get the three new options, followed by the last four of the old ones. I saw the same effect when I took out the `FormData.step.length = "1";' line, so I am assuming that this line is not compatable for some reason.

My second problem is that, apparently, none of the combo boxes ever change anything for Internet Explorer users. The code is basically the same for all the functions (including the example above), but most of them only change the value of a few text boxes. Is there some oddity with IE whereby it cannot use a script like the one above?

Thanks for any advice!

Kor
04-27-2005, 04:12 AM
FormData.name.value looks incorrect to me, as name is a reserved javascript word, thus it can not be used as a variable/function name.

FormData.step.length = "1"; looks also incorrect, as lenght is an atribute who need numbers as values, not strings

What suppose to do your code?

scragar
04-27-2005, 04:27 AM
you want to set the length of the options array to 1, not an object.

Matthew Perciva
04-27-2005, 05:48 PM
I made a few changes, and managed to get things to work. I fixed the first problem by looping through the array and setting each to null, until there was only one left. The problem with the latter was that I had not set the form up correctly: other browsers seemed able to work it out themselves, but IE could not for whatever reason.

The script takes input from a combo box, then replaces the values in different elements on a form. I've not seemed to have any problems with the text box named `name', though I did have trouble when I called one `enum' (obviously because this is a reserved word - I just renamed it to fix that problem).

The script also adds/removes items from a second combo box, and this is what I want to expand upon next. I have added optgroups to sort the second combo box, but I want to have an option to enable/disable different groups. I know that in the html I can do `optgroup label="blah" disabled' for this effect (though it doesn't seem to work in IE again - is this just me, or is there a problem with IE and disabling optgroups?). I want to add this to my JavaScript, but have not been able to find how to access optgroups here. I assume it's `document.form.select.foo.disabled = true', but I cannot find what foo is. Any suggestions?

Thanks!