Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to set a variable to equal current users username?

As the question stated above I am trying to set a variable in my javascript to be the value of the users username. This is how my code is set up:


function submitApproveModal(){ 
  this_file = currentFile;
  
  var approvers = "";
  if(document.getElementById('approvers').checked){
    approvers = '<?php $_SESSION['username'] ?>';
  }
  
  approveFileAjax(this_file.uid, approvers);
}

I know this is not the way for it to work and wondering how exactly can I rewrite my code so that approvers will equal the users username?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You simply forgot the "echo":

approvers = '<?php echo $_SESSION['username'] ?>';

But as mentioned before, mixing up Javascript and PHP is a bad idea.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading