Is there ANY way to trigger an AJAX event on a button that is clicked, or an image that is clicked?
I have PHP code that validates an address that is entered into text fields on a form. I can call that code when a radio button is clicked, or a checkbox is clicked, etc… but cannot figure out a way to call that code when a button is clicked.
There is no field type “button”, and if I create a Label field and put an HTML button in it then it doesn’t catch the “onClick” with an AJAX event.
Please point me in the right direction if I am going about this all wrong.
I am still a new Scriptcase User…
Thanks!
If you need to fire code on a button you need to create a button and by doing that you choose if it will be a php type button or javascript type button. Then you get a field in which you can enter your code.
That doesn’t achieve the AJAX type result I am looking for. When I click a PHP type button it goes to an “OK” button and the page is sent to the server and back.
The AJAX event just fires of the little bit of PHP code that I want to run and does it perfectly. I just can’t get an AJAX event to fire from a button… any form type HTML element seems to let me… RADIO, CHECKBOX, even text fields.
Thanks for your suggestion Albert, but It doesn’t produce my desired result.
hey dude:
why dont you try to use an image field, set him to a button img and use the onclick ajax event?
Regards.
If it works it would be great, but afaik the event doesn’t trigger. But that might have been solved as I never used it since I reported that.
No you are right Albert… It wont even let me create an Ajax Event for HTML Image Type of field. If it did, that would be perfect for my use!
Thanks for the suggestions so far… any other ideas?
Well that’s a solution, my report was ‘fixed’ by disallowing the event Seriously I can see why. But perhaps the following is a suitable solution:
You can create a link on an image. A dirty trick I sometimes use is that I put a blank application in between and then use sc_redir to move to the desired application after doing some things. You can create a link to a blank application, even pass parameters to that if you define globals in your blank application to map your fields against.
But I don’t know if it would be helpful for you though.
Well… i can offer you something else. in your form, create a field of the type label and in the label text you can use html content such as
<a href=[the php file to execute the code]>link</a>
hope this helps.
Regards
It wont even let me create an Ajax Event for HTML Image Type of field.
I have the same problem. Why I can’t make a image html onclick ajax event?
Don’t know why, but it’s not supported. It’s an issues since I work with SC.
I doesn’t matter. I solve the problem making a text input field and defined like label, then onload :
{start}=’<a id=“id_sc_field_start” class=“scButton_default” style=“vertical-align: middle; display:inline-block;”>Start</a>’;
then in “ajax events” start_onClick event:
$javascript_function = ‘myStartjsFunction’; // Javascript function name
sc_ajax_javascript($javascript_function);
myphpstartfunction(); //this function insert info into db
Is working nice! hehehe.
hi apolo512
how you manage to add ajax event to label field?
well, update: i could manage to create text field and marked it from inside the filed properties to: label = Yes.
configuring it as image in onLoad e.g. {field}= “<img src=’…/_lib/img/sys_image1.png’></img>”;
but i couldn’t make it ajax -> onClick to show a block using: sc_block_display(myblock, ‘on’);
any idea how to make this work?
Hi, due to I couldn’t add ajax event or link to an image, I took another way. My label field is {start} but in “onload event” y convert to a button, then you can add ajax events to a button.
This will allow the image to be a button and being recognized under the Ajax event:
{Generate}=’<img src="…/_lib/img/grp__NM__btn__NM__generatebutton.png" style=“width:100px;height:25px;” id=“id_sc_field_generate” class=“scButton_primary” style=“vertical-align: left; display:inline-block;”>’;
convert to buttn? how?
Thanks I will check this really adds value as sc has limitation in this regard
This statement will allow a sc text field to function as an image button (defined in onLoad event) and being recognized under the Ajax event in SC Form Application:
{Generate}=’<img src="…/_lib/img/grp__NM__btn__NM__generatebutton.png" style=“width:100px;height:25px;” id=“id_sc_field_generate” class=“scButton_primary” style=“vertical-align: left; display:inline-block;”>’;
Breaking down the statement syntax:
{Generate} => field name called Generate, with Data Type = Text and Label Field = Yes
“…/_lib/img/grp__NM__btn__NM__generatebutton.png” => image file called “grp__NM__btn__NM__generatebutton.png” located at “…/_lib/img/”
"style="width:100px;height:25px; " => size of your image
" id="id_sc_field_generate " => the element that identify the {Generate} field, SC will create using the syntax “id_sc_field_xxxxx” where xxxxx is the field name created and all in lowercase
"class=“scButton_primary” style="vertical-align: left; display:inline-block;" => this will show the field “Generate” as a button
Under the Ajax events,
- create a New Ajax Event for the field “Generate” with processing option as “onClick”
- Within the Generate_onClick event, enter the code you want to perform when the Generate button is clicked.