Fixed a few bugs. But found that type-casting is not working between PHP and Javascript. Consider sending JSON over AJAX and persisting JSON. Consider restoring values in HTML with Javascript instead of PHP.