Using Ajax Processing(Refresh)

Using Ajax Processing(Refresh)

In this article we will learn how to use the "Ajax Processing" function available in Scriptcase. As an example, we have a control-type application with two select fields ("state" and "city"), where when we select the state we will use ajax processing to bring us, in the city field, only the cities of the state selected.

To achieve such an effect, we need to maintain some sort of relationship between our tables. In our case, the city table has a field that holds the id of its state:

Tabela adm_estados:

 

Tabela adm_cidades:


First, we need to create the control application and the two fields we will use


 

Next, we need to create the SQL commands of our fields, let's start with the state field. Select the field from the interface, and go to the Lookup Editing option and assemble your select, below see how we set up ours:



Query SQL - state
SELECT EstadoID, NomeEstado
FROM adm_estados
ORDER BY NomeEstado


Next, we will configure the SQL command of the city field:



Query SQL - city
SELECT estado, cidade
FROM adm_cidades
WHERE state= '{state}'
ORDER BY cidade


Note that in this second we make use of a where cláusua, to filter the cities by the chosen state.

Finally, go back to the field state and look for the Ajax Processing option. Coming to it, select the Use Ajax option to reload other select, double select, radio, and checkbox fields, and then select the city field.



Run the app and see its operation:



    • Related Articles

    • Using sc_ajax_refresh()

      -Create a grid -At the Ajax Event -New Ajax Event: -Select the Event onClick and the desired field, and create: -Add the following macro: sc_ajax_refresh (); -When clicking on the record in that field, the page would be reloading Corresponding ...
    • Using ajax: onChange events

      In this article we will see how the onChange event works, available in Scriptcase. It is triggered when the object, which makes use of it, has its value changed. Down below is an example of using this event. We will use an order items form, we will ...
    • Using friendly URL

      The friendly URL was included from Scriptcase 7, in order to make the URL, of the applications generated by Scriptcase, cleaner and easier to associate them with applications. For example, using friendly URLs the link to a Scriptcase application ...
    • Using Languages in Scriptcase

      In Scriptcase you have the option to standardize the language information quickly and uncomplicated. Using the feature you can change LANGUAGES entire textual structure of the project, since this native messages Scriptcase own name to fields and ...
    • Using the Database Builder

      The DataBase Builder is a Scriptcase 'DBMS' (Database Manager System), this tool allows you to create tables, modify the structure of your tables, generate ER diagrams (Entity x Relationships), perform the export of the tables among other things. ...