I just started web development and it’s a whole different ball game from the client! I did a search on notes.net, and I think this is supposed to work, but… it doesn’t. Can anyone see what I’m doing wrong? (all the other validations where I check for null values are fine.)
I have two fields:
Field1(combobox, default value is “1”)
Choice1|“1”
Choice2|“2”
Field2 is text, and is only required if Field1 == “2”.
I have these lines in the JS Header, in a validations function, at the end of the validations that work:
if (frm.Field1.options[selectedOption].value == "2" && frm.Field2.value == "")
{
alert ("Please enter a value in Field2.");
frm.Field2.focus();
return(false);
}
frm is defined at the top of the JS Header and initialized in OnLoad (frm = window.document.forms[0]
Subject: RE: JavaScript validation - trouble accessing combobox value
Hi Stan,
Thanks for your response. Unfortunately, still didn’t work. I see “error on page” at the bottom of the screen. Not sure how else to debug this. All I know is that it’s coming from these few lines, because if I take them out, the “code” works… Do you see anything else?
Subject: RE: JavaScript validation - trouble accessing combobox value
In your original post, you say that you set up your options for the combobox like this:
Choice1|“1”
Choice2|“2”
Did you actually type in those double quotes? If so, then the alias value being saved will look like "“1"” or "“2"”, throwing off the value you are checking for. You don’t need to add quotes when specifying choices for a combobox. Those values will be saved as text anyway. Try taking out those double quotes and see if Stan’s suggestion works.
If you didn’t type in those double quotes, then it’s back to the drawing board!
Subject: RE: JavaScript validation - trouble accessing combobox value
R,
Stan has a typo in his code. The following…
if (frm.Field1.options[frm.Field1.selectedOption].value == “2” && frm.Field2.value == “”) {
…should be…
if (frm.Field1.options[frm.Field1.selectedIndex].value == “2” && frm.Field2.value == “”) {
Also, since you’re a newbie JavaScript coder, it is not a good idea to leave out relevant code. What is frm? Am I supposed to assume you properly set this up as…
Subject: RE: JavaScript validation - trouble accessing combobox value
Indeed – I just pasted what Rachel already had and added the reference chain for selectedBlurryBit. I should have checked to see that selectedBlurryBit was the right BlurryBit. Mea culpa.
Subject: RE: JavaScript validation - trouble accessing combobox value
Domino should be feeding the alias as the .value and the “visible value” as the .text of the option. (One may have to go spelunking for the text node and its nodeData in some browsers, but it shouldn’t be the case for the mainstream stuff.)