Is there a possibility to autoload available data when data entering to top fields
Like in the following example.
Autoload available data when data entering to form
-
- AppGini Super Hero
- Posts: 121
- Joined: 2020-02-16 16:29
Re: Autoload available data when data entering to form
Hi,
yes you can. Attach a on "change" event handler to the selection box and if the necessary information is available, catch the data via ajax and fill the cases.
yes you can. Attach a on "change" event handler to the selection box and if the necessary information is available, catch the data via ajax and fill the cases.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
-
- AppGini Super Hero
- Posts: 121
- Joined: 2020-02-16 16:29
Re: Autoload available data when data entering to form
Thanx pböttcher for the idea.
Can you help me a little bit with some elaboration....
Re: Autoload available data when data entering to form
Hi,
can you be a bit more specific. Otherwise it is difficult to help further. What kind of dropdown do you have? What field do you need to fill? ....
can you be a bit more specific. Otherwise it is difficult to help further. What kind of dropdown do you have? What field do you need to fill? ....
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
-
- AppGini Super Hero
- Posts: 121
- Joined: 2020-02-16 16:29
Re: Autoload available data when data entering to form
Thanks and here are the details
- Attachments
-
- epid.rar
- (2.96 KiB) Downloaded 76 times
-
- 1.png (38.74 KiB) Viewed 1938 times
Last edited by sathukorala on 2020-12-05 01:49, edited 1 time in total.
-
- AppGini Super Hero
- Posts: 121
- Joined: 2020-02-16 16:29
Re: Autoload available data when data entering to form
This is the actual page
I have attached the project file too
User selects 1 to 4 and they are all option lists with predefined values
COVID cases is a variable field and it should be loaded when all 1 to 4 are selected and if a record is available user should see the edit page instead of Save New button
- Attachments
-
- epid.rar
- (2.96 KiB) Downloaded 77 times
-
- AppGini Super Hero
- Posts: 121
- Joined: 2020-02-16 16:29
Re: Autoload available data when data entering to form
I found a solution which works !!!
If above 4 dropdowns are selected and when the "Time Period" dropdown is clicked, AJAX call for the ajax.php with data parsing and if
any matches are found the user prompted to be redirected to the view/edit page
This goes in the hooks/table_name-dv.js
This goes in the hooks/ajax.php
Experts comment and refine the code
If above 4 dropdowns are selected and when the "Time Period" dropdown is clicked, AJAX call for the ajax.php with data parsing and if
any matches are found the user prompted to be redirected to the view/edit page
This goes in the hooks/table_name-dv.js
Code: Select all
$j('#time_period').on('click', function(){
load_details();
});
function load_details(){
if (($j('#time_period-container').select2('val') == '{empty_value}') || ($j('#province-container').select2('val') == '{empty_value}') || ($j('#district-container').select2('val') == '{empty_value}') || ($j('#hospital-container').select2('val') == '{empty_value}')){
$j('#cases').val('');
}else{
time_value = $j('#time_period').val();
province_value = $j('#province').val();
district_value = $j('#district').val();
hospital_value = $j('#hospital').val();
$j.ajax({
url: 'hooks/ajax.php',
data: { time_column : time_value , province_column : province_value , district_column : district_value , hospital_column : hospital_value},
success: function(data){
if (!$j.trim(data)) {
$j('#cases').val('');
}else{
alert ("Record Exists !!! Click OK to redirect to the record view page (If you have permission you can edit)");
window.location = "COVID_cases_view.php?SelectedID="+data;
}
}
});
}
}
Code: Select all
<?php
$currDir = dirname(__FILE__) . '/..';
include("$currDir/defaultLang.php");
include("$currDir/language.php");
include("$currDir/lib.php");
$time = makesafe($_REQUEST['time_column']);
$province = makesafe($_REQUEST['province_column']);
$district = makesafe($_REQUEST['district_column']);
$hospital = makesafe($_REQUEST['hospital_column']);
$sql = "SELECT id FROM covid_cases WHERE time_period = '{$time}' AND province = '{$province}' AND district = '{$district}' AND hospital = '{$hospital}'";
$data = sqlValue($sql);
echo $data;
?>