Cannot hide fields using ajax_onclick

What am I doing wrong here? Just a simple ajax to hide some fields and its not working! :frowning:


if ({employ_current} == 'Yes')     // Display field
{
    echo 'show';
    sc_field_display({employ_type}, 'off');
    sc_field_display({employ_employer}, 'on');
    sc_field_display({employ_position}, 'on');
    sc_field_display({employ_practice}, 'on');
    sc_field_display({employ_worknature}, 'on');
}
else      // Hide field
{
    echo 'hide';
    sc_field_display({employ_type}, 'off');
    sc_field_display({employ_employer}, 'off');
    sc_field_display({employ_position}, 'off');
    sc_field_display({employ_practice}, 'off');
    sc_field_display({employ_worknature}, 'off');
}


[ATTACH=JSON]{“data-align”:“none”,“data-size”:“large”,“data-attachmentid”:86037}[/ATTACH]

[ATTACH=JSON]{“data-align”:“none”,“data-size”:“large”,“data-attachmentid”:86039}[/ATTACH]
[ATTACH=JSON]{“data-align”:“none”,“data-size”:“large”,“data-attachmentid”:86040}[/ATTACH]

Screen Shot 2019-01-09 at 6.21.07 pm.png

Screen Shot 2019-01-09 at 6.20.36 pm.png

Screen Shot 2019-01-09 at 6.20.08 pm.png

Screen Shot 2019-01-09 at 6.19.37 pm.png

Hallo,

as far as I see, you cannot use this macro in Ajax (ajaxOnClick). Online Help shows a scope without Ajax:

[ATTACH=JSON]{“data-align”:“none”,“data-size”:“full”,“title”:“Unbenannt.JPG”,“data-attachmentid”:86048}[/ATTACH]

Hint:
Maybe you should use a short JavaScript to hide the field.

Sincerely

Unbenannt.JPG

Thanks for the reply!

Do you know if maybe this has this changed recently? I am certain I have used this function before in old projects, and yesterday while troubleshooting I found this document from Scriptcase which clearly shows that it should work.

https://support.scriptcase.net/es/article/1082-using-the-sc-field-display-and-sc-label-macro-in-an-ajax-event

Just a bloody typo! Field name doesn’t match the field name in the code. No error thrown, thanks a lot SC!

Sorry, has nothing to do with SC, but php. Variables are declared on the fly.

So why did PHP stop processing on the first function call that contained an invalid field name? It should have just kept going and correctly hidden the subsequent fields. However it seems like it caught an error (didn’t display it) and then silently died.