Show/Hide fields on Edit page

In PHPMaker2020 I am using the below script to hide or show fields based on selection from dropdown list and it’s working fine in List page while in Edit page i have to deselect and reselect values from the dropdown list in order to work, I am not so good in javascript any help is appreciated.$(document).ready(function(){
$(“#r_Fridge_Serial_Number”).hide();
$(“#r_Contract_Number”).hide();
$(“#r_SAP_Number”).hide();
$(“#r_Vendor_Number”).hide();
$(“#r_Custom_Release_Number”).hide();
$(“#r_Clearance_Agent_Name”).hide();$(“#x_File_Type_1”).change(function() {
var str = $(“option:selected”, this);
//Fridge Contracts
if (this.value == “Fridge Contracts”) {
$(“#r_Fridge_Serial_Number”).show();
$(“#r_Contract_Number”).show();
}
else {
$(“#r_Fridge_Serial_Number”).hide();
$(“#r_Contract_Number”).hide();
}//Finance Documents
if (this.value == “Finance Documents”) {
$(“#r_SAP_Number”).show();
$(“#r_Vendor_Number”).show();
}
else {
$(“#r_SAP_Number”).hide();
$(“#r_Vendor_Number”).hide();
}//Import Shipments
if (this.value == “Import Shipments”) {
$(“#r_Custom_Release_Number”).show();
$(“#r_Clearance_Agent_Name”).show();
}
else {
$(“#r_Custom_Release_Number”).hide();
$(“#r_Clearance_Agent_Name”).hide();
}
});
});

in the Edit-Page [startup script] I just check the current state of the object and set the state accordingly:

var account_status = $( "#x_account_status option:selected" ).value();
if(account_status == 1)
	$("#r_cancellation_date").hide();
else
	$("#r_cancellation_date").show();

$doc.ready(func() {

}the JS experts here can probably give you a better solution.

sticcino wrote:
in the Edit-Page [startup script] I just check the current state of the
object and set the state accordingly:

var account_status = $( "#x_account_status option:selected"

).value();
if(account_status == 1)
$(“#r_cancellation_date”).hide();
else
$(“#r_cancellation_date”).show();$doc.ready(func() {

}the JS experts here can probably give you a better solution.
Thank you for help but unfortunately i am not a JS expert, Can someone help me here please?

  1. Remove the enclosing “$(document).ready(function(){” and “});”
  2. If “File_Type_1” is a lookup field, use “updatedone” event, see the topic Server Events and Client Scripts > Client Scripts > Table-Specific → Add/Copy page > Client Script > Example 3 in the help file. (v2020)

No it’s a select field, i have removed enclosing “$(document).ready(function(){” and “});” from Client Scirpts–>Edit Page but all the function messed up and nothing happened.
I am wondering if this line $(“#x_File_Type_1”).change(function() is correct for a selected value from the drop list?

tamersherif wrote:
I am wondering if this line $(“#x_File_Type_1”).change(function() is correct for a selected value from the drop list?Yes, it is correct. However, you also need to fire this “change” event after the options are updated. Hence, arbei wrote:
If “File_Type_1” is a lookup field, use “updatedone” event, see the topic Server Events and Client Scripts > Client Scripts > Table-Specific → Add/Copy page > Client Script > Example 3 in the help file. (v2020)
(A field with “SELECT” Edit Tag is a lookup field.)You may also see the examples about Client Side Event (see the topic Field Setup in the help file) and the jQuery .fields() plugin (see the topic Server Events and Client Scripts > jQuery .fields() Plugin in the help file).