'JavaScript and PHP values toggle

I have index.php page and I have this there:

$pv->showHidden = isset($_POST['showHidden']) ? intval($_POST['showHidden']) : 0;
$pv->sendHidden = isset($_POST['showHidden']) ? 0 : 1;

and then I have this:

<input type="image" id="btnShowHidden" src="images/hide.gif" onclick="showHiddenRecords(<?php print $pv->sendHidden; ?>);" />

I have JavaScript that has this function:

function showHiddenRecords(x){
 alert(x);
 var n = new Object();
 var showHidden;
 if(x=1){Y=0;} else {Y=1;}
 n.showHidden = Y;
 Ajax.Post("index.php", n, pg.test(x));
      
}

What I am trying to do is to toggle the value of $pv->showHidden, so if it is 1 (already selected) then it will become 0 and vice versa, but the logic isn't working.
Thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source