I have a checkbox, I need it to keep its status(checked or not) after sending the POST.
This is my code, the condition works, but the function call is not there.Is there a possible error somewhere?

<input class="checkboxDiv_input" type="checkbox" name="checkbox_work" value="Yes" id="checkbox_work" onclick="checkAddress(this)">
<?php
	if(isset($_POST['checkbox_work'])) {
	if($_POST['checkbox_work'] =='Yes') {
		echo'<script type="text/javascript">checkAddress("checkbox_work");</script>';
	}
}
?>
<script>
		function checkAddress(checkbox)
		{
		if(checkbox.checked)
		{
		$('#endWork').attr('disabled', true);
		} else {
		$('#endWork').attr('disabled', false);
		}
		}
	</script>
  • The error is that you are mixing php and js code – Worrisome Wombat Aug 24 '19 at 12:47
  • Worrisome Wombat, but how then to do it? – Blushing Buzzard Aug 24 '19 at 12:49
  • Blushing Buzzard, separate the front and back code.It is impossible to figure out or try to debug the current code – Worrisome Wombat Aug 24 '19 at 13:11

2 Answers 2

If you want to call the execution of JS-code in the context of PHP - it’s not possible(it’s possible, but you can’t do it, in your case for sure).

You need to handle the form submission a little differently(or what do you have there?), You must call the JS code in the browser, where it should be, which will check your address, and if it is correct, send the data to the server.But on the server, you will have to get this data check again, but in PHP, because you cannot trust incoming data, JS validation is very easy to get around.
Wrap your govnokod in a redi document and it will work.