How to programmly change a button's caption?

as in the title, could change the button’s caption in the PHP code?

Not directly. You can apply a javascript procedure in your html and use a sc_macro in php to call that.

Still have no idea, could you please show me how to do?

Thank you very much.

I’m not a javascript guru but you need to retrieve the object you need to change the title of. Then create a piece of javascript to put into the generated code, i.e. in the onapplicationinit. Then you need to call this javascript function by php with a sc macro: sc_ajax_javascript

The next sample sends data to a javascript procedure, it’s not doing what you want, but the idea should be clear:


echo '<script type="text/javascript">function disp_a(xfrm,xuri) { parent.document.getElementById("id-iframe-widget1").src="../form_sideline/form_sideline.php?glob_id=newcustomer&glob_shopid=generic"; } </script>';

$javascript_function = 'disp_a'; // Javascript function name
$javascript_parameters = array( // Javascript function parameters, add as many as needed
'',
'');


// Call javascript function
sc_ajax_javascript($javascript_function, $javascript_parameters);

oh Albert, I think he is lost more now lool

I like it when you say I’m not java guru, see not me too, but at least you don’t scare of the java code like I do, sometimes is definitely needed then I seek for help, but if I can avoid it, that is the best :slight_smile:

for example, did you try to make the button title that you want to change as a variable? then you can define this variable based on condition in some event…

hmmm wait a minute, do you mean the “alt” “title” thing the light-yellow “caption” ? the hint? or the button label itself?

Hello:

I think that for us to give a better answear we need to know what kind of button, why and when you wanna change the caption.

Regards

Well a button is a button. It has some text in it and I assume that this caption needs to change depending on some data on the form. I solve these issues by setting buttons on and off but changing captions and / or behaviour would be preferabel. I never looked into that just because I want to avoid javascript.

Well yes:

But how about he want to change the caption of the button “Add” to “Include” in all the project… then the easiest way wold be to modify the {language_variable} that’s why I ask.

Regards

Thank you very much.
I explain why I want to change the button’s caption in the Grid’s OnScriptInit event.

See the attachment, I make some buttons to do the Grid’s filter, for the current user’s click, it change to the current user’s all item/todo item/done item, etc.

Then I want to show the items count in the button’s caption, that’s reasonable, you won’t want your user only switch to the page to see how many records in the page. If can show in the button’s text, that’s obverse.

I tried to set the language var programmly, and it works to the page’s header, in the code, I can change the page’s header through a code like this:

{lang_tbl_zc_request} = {lang_tbl_zc_request} . " – <font color=red><B>" . {lang_btn_itemtodo} . “</B></font>”;

That’s the picture’s right top caption, we can easily change the page’s header through the above code;

But we cannot change the button’s caption through that, Like: {lang_btn_all} = {lang_btn_all} . " (100)";

It just cannot work, even put the code to the OnApplicationInit event.

It’s a normal require to easily change a button’s caption, is that right?

1.jpg

hi again, you mean something like blogs or social networks, to show My todo (3) and my done (20)

okay, same idea, create a variable in your onScriptInit and have it calculate that number for your items

then in your button text put something like “My todo [glob_mytodo]” this way you can add to your calculation code that if <=0 then show nothing, otherwise, show this number to user next to the button title, woudn’t work this way? seems simple, not sure

WOOOOOO MikeSamaChanSempai good one bro.=D

hi dude :smiley: is that Chinese?

@MikeDE good idea, but have you try it?
I got like this:

Maybe the button’s caption just ignore the global var.

2.jpg

@kafecadm, forget it, got what you mean, interesting approach though we don’t use that around, Albert can be Sempai lool

@jerry oh means global will not work in buttons? WTF!! can you try java type button!? i don’t have my sc dev with me to try, perhaps Sempai kafecadm can tell us how to use that in buttons :smiley:

Did you ever figure this out?

This is now managed using the sc_btn_label(“btn_name”, “new_label”) macro.

1 Like