RadioBtn field's onChange JS code not working

Hi all,I have a dropdown combobox field called “DeliveryEmpList” that I want to be invisible if the current user does not have the “WarehouseMgt” userRole assigned to him or if the value of a radio button called “DeliveredBy” does not have the “Staff Member” item selected. The Hide-When attribute for the “DeliveryEmpList” field is:

!@IsMember(“[WarehouseMgt]” ; @UserRoles) & DeliveredBy != “Staff Member”

The onChange JS code for the “DeliveredBy” field is:

var f = document.forms[0];

if (f.DeliveredBy.options[f.DeliveredBy.selectedIndex].text == “Staff Member”) {

f.DeliveryEmpList.style.visibility = ‘visible’;

f.DeliveryEmpList.focus();

}

else {

f.DeliveryEmpList.style.visibility = ‘hidden’;

}

_doClick(‘$Refresh’,this,null);

I even tried to modify the code as follows and still doesn’t work:

var f = document.forms[0];

if (f.DeliveredBy.options[f.DeliveredBy.checked].text == “Staff Member”) {

f.DeliveryEmpList.style.visibility = ‘visible’;

f.DeliveryEmpList.focus();

}

else {

f.DeliveryEmpList.style.visibility = ‘hidden’;

}

_doClick(‘$Refresh’,this,null);

Any assistance would be greatly appreciated.

Thanks,

Dan

Subject: RadioBtn field’s onChange JS code not working

You didn’t mention the context. I will assume it is being run in a browser since you mention JavaScript.

Hide-whens are executed at the point when the page is being rendered to the browser. They are not affected by anything changing on the webpage until it gets submitted back to the server. In other words, there is no interaction with the server until the page is sent back.

Subject: RE: RadioBtn field’s onChange JS code not working

NO.Changing the visibility without reloading the page works just fine. But one must generate HTML for all items (Form property, “On Web Access” section of “Defaults” [beanie] tab). Otherwise hidden items are not generated.

Subject: RE: RadioBtn field’s onChange JS code not working

I do have that selected already.

Dan

Subject: RE: RadioBtn field’s onChange JS code not working

Check to be certain your comparison is working.Add a bunch of alert statements to the code and watch as it executes.

alert( f.DeliveredBy.options[f.DeliveredBy.checked].text );

Watch to see if you get the javascript failure yellow icon in the lower left of the browser window.

Subject: RE: RadioBtn field’s onChange JS code not working

“Generate HTML for all fields” will create an for fields that are hidden by a hide-when, so changing the CSS visibility or display for the element won’t be able to create a usable field where there was none before.

In order to fix the problem, Dan, you’ll need to separate the userrole-based hide-when from the DeliveredBy display/hide

function. That means that the hide-when should become simply:

!(@UserRoles = “[WarehouseMgt]”)

Use the HTML Attributes event of the DeliveryEmpList field to control the as-served CSS hiding:

@If(DeliveredBy = “Staff Member”; “”; “style="visibility: hidden;"”)

That way, the drop-down version of the field is available in the HTML as long as the user has the correct role, but it will only be visible/usable if the DeliveredBy field contains “Staff Member”. Your JavaScript will be able to change the visibility in the browser, depending on the value in DeliveredBy.

Now, you shouldn’t need to do a Domino refresh, so you can get rid of the call to _doClick(). As I understand it, DeliveredBy is a radio button field, so the code should be something like this:

empList := this.form.elements(“DeliveryEmpList”);

if(this.checked && this.value == “Staff Member”) {

empList.style.visibility = “visible”;

empList.focus();

}

else {

empList.style.visibility = “hidden”;

}

Subject: RadioBtn field’s onChange JS code not working

You didn’t actually say what wasn’t working…field hidden but not showing, showing but not hiding, etc…

But no matter…you could just lose the JavaScript and use a Notes feature to get what you want. Just edit your DeliveredBy field and check the “Refresh fields on keyword change” feature. It works on the web just like it does in Notes. The penalty for using the Notes feature is a flash on any change to DeliveredBy…but it sure is easy!