Click function

I have 2 different projects that after they were converted to PHPMaker 2021.0.12 version the “click” functions stop working.This function appeared under edit tag → client side event.Here is the function:

{ // keys = event types, values = handler functions
	"click": function(e) {
		   if ($(this).is(':checked')) {
		   	 $('#x_TotalValue').val(0);
		   }
	}
}

When I click the checkbox the value of the variable TotalValue is supposed to reset to zero but it is not.Any help will be much appreciated.

You may try to use “change” event and check this.value. You may test by using console.log(this.value) first.

Here is what I have… it is located under “Client Scripts>>Table-Specific>>Add/Copy Page>>Startup Script”

$(document).ready(function() {
    // Form load event
    $('input:checkbox[name="x_M_HazardRemoved[]"]').click(function() {
        // Click event
        if ($(this).is(':checked')) {
            $('#x_M_TotalValue').val(0);
        }
    });
});

It does not show any errors during generation or when run on the site but it won’t do what I expect. Which is that when I click the radio button the value of M_TotalValue resets to zero.Thanks… I am running the latest version of PHPMaker.

napiedra wrote:

This function appeared under > edit tag ->client side event

{ // keys = event types, values = handler functions
 	"click": function(e) {
...
 	}
}

arbei wrote:

You may try to use “change” event and check this.value. You may test by using console.log(this.value) first.

e.g. if you use the CHECKBOX Edit Tag, (v2021)

{ // keys = event types, values = handler functions
 	"change": function(e) {
 	 	console.log(this.value);
 	 	// Your code
 	}
}

I followed the instructions above and this is what I typed:

{ // keys = event types, values = handler functions
  "change": function(e) {
    console.log(this.value);
    if ($(this).is(':checked')) {
      $('#x_M_TotalValue').val(0);
    }
  }
}

Still I get no errors generating or running the website but the click does not reset the value to 0. I also added the console.log(this.value) but I don’t know where to look to get logs.Any help will be appretiated.

Read Console overview.

As arbei mentioned before, you should check the output of this code: console.log(this.value); from Console section of your browser (press F12), and then use this value in your if … code block to implement your business-logic.

This is what I have and it won’t generate any errors but the console only shows the same script. Yet it is not working

Found under src: userevent.js?v=24.16.0

{ // keys = event types, values = handler functions
  “change”: function(e) {
    console.log(this.value);
    if ($(this).is(‘:checked’)) {
      $(this).fields(“#x_FlightValue”).value(“0”);
      $(this).fields(“#x_FlightValue”).visible(True)
    }
  }
}

This is the output of the console.log

ew.events = {
    AssessmentDetail: {
        x_HazardRemoved: {
            change: function(e) {
                console.log(this.value);
                if ($(this).is(":checked")) {
                    $(this).fields("#x_FlightValue").value("0");
                    $(this).fields("#x_FlightValue").visible(True)
                }
            }
        }
    }
};
ew.charts = {};
ew.clientScript = function() {}
;
ew.startupScript = function() {}
;