How to hide a button of form using a IF statement

Dear all,

I have to solve this matter becouse it’s blocking me.

I did a single record master form and two detail forms .
In the master form I have a name of user and if the select count give me a result >0 on the form table means that I have to hide the “New” button.
Otherwise the user has still no registration and so I can show the new button.

I’ve founded “sc_apl_conf” macro but probably within “onchange Ajax event” they do not work.

Onchange code

// SQL statement parameters
// Check for existing record
$check_sql = “SELECT COUNT(*) FROM med_therapy_m WHERE med_therapy_m.user_id = {user_id}”;
sc_lookup(dataset, $check_sql);
$check_flag = {dataset[0][0]};
echo “CFlag ON Change” .$check_flag;
IF ($check_flag > 0)
{
sc_apl_conf(“form_med_therapy_m”, “insert”, “off”) ;
sc_apl_conf(“form_med_therapy_m”, “add”, “off”) ;
}

I’m stucked and I’ve no idea how to conditional hide the button. Any suggestion will be very hepful.

http://imageshack.us/photo/my-images/834/hideq.png/

Re: How to hide a button of form using a IF statement

From reading the help:

The user can determine if a Form will start in insert mode

i.e.: onInit, onLoad, onSubmit, etc.

I believe sc_apl_conf() is designed to update the button/form-state when it is loaded, not just on a call. Meaning you would have to reload the form to update the button.
If you need to disable the button when you change a value on the form, then you will have to execute some javascript and find the id of that button and disable it.
google: javascript disable button

Here is an example of a live edit form I posted on some time ago that may help as well:
http://www.scriptcase.net/forum_en_us/index.php?topic=1595.0

Regards,
Scott.

Re: How to hide a button of form using a IF statement

Thanks !
Reversing the functioning, do you think that it’s possible to show the button only when the IF ($check_flag = 0) .

There is also this macro command : sc_btn_display(‘new’, ‘off’);

I think the problem is the same you describe on your post on both cases.

The “id” of button could be “sc_b_new_t” but I really don’t know how to write the command.
Giovanni