Change Field value depends on current date

I used a custom script to set value in field depends on getting a current day but not working

cur_frm.cscript.custom_validate = function(doc) {
	if (doc.ends_on == get_today()) {
		cur_frm.set_value("course_status", "Completed");
		validated = false;
	}
}

Please remove the statement validated = false;, it should work.

@nabinhait thanks for your support I got this console message

Please use frappe.datetime.get_today instead of get_today. It will be deprecated soon.

and I change the code but still not working my final code

cur_frm.cscript.custom_validate = function(doc) {
	if (doc.ends_on == frappe.datetime.get_today()) {
		cur_frm.set_value("course_status", "Completed");
		
	}
}

@nabinhait
Any update

Is custom_validate a valid field in your form? If you want to set the field on change of ends_on field then you should use

cur_frm.cscript.ends_on = function(doc) {
	if (doc.ends_on == frappe.datetime.get_today()) {
		cur_frm.set_value("course_status", "Completed");
		
	}
}

@Alaa_Badri
What is the field type of course_status?

Thanks for your response
it’s working only for < condition but not working for

condition and when put only one = it’s change course status for every change in ends_on filed and also i need the system check this date automatically not when i change it like converted sales order to over due after due date

select