I am facing a challenge where I need to automatically fill in a field with the email address of the user who logged into the system. The issue is that this application is used by different clients, so I need to dynamically add the necessary code to the external JavaScript file. I have been experimenting with JSON data, but I am unsure if this is the right approach.
Here is an excerpt from my PHP code:
<?php
$myemail = $this->session->userdata('USER_EMAIL');
//echo $myemail;
Following that, I have the following snippet:
var $jsonEmail = trim(json_encode($myemail));
Then, in my custom JavaScript page, I included this:
var jsonObj = $jsonEmail;
document.getElementById("email-12").innerHTML=jsonObj.value;
Unfortunately, the solution does not seem to be working as expected. As I am relatively new to this, I am struggling to identify what I may be doing wrong. Any guidance or assistance on this matter would be greatly appreciated.