I want to populate the extract records from mysql database. I am using ajax javascript to do the request.
The problem is not populating to input type text area array just bec. of this error.
I want to populate the extract records from mysql database. I am using ajax javascript to do the request.
The problem is not populating to input type text area array just bec. of this error.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Naimish MakwanaPosted Mar 27, 2024, 6:08 AM
The error message “Uncaught TypeError: Cannot set properties of null” typically means that you’re trying to access or modify a property on an object that doesn’t exist or is
null.In your case, it seems like the issue is with this line of code:
Here, you’re trying to set the value of an element with the id
"section1_target_action0". However, the error suggests that there’s no such element in your HTML.The problem might be that your textarea doesn’t have an id. You can try adding an id to your textarea like this:
This way, your JavaScript code should be able to find the textarea and set its value. Please make sure the id you’re using in your JavaScript matches the id in your HTML. Also, if you have multiple textareas, each one should have a unique id.
Thanks
Mrunali SawantPosted Jun 6, 2024, 5:28 AM
The "Uncaught TypeError: Cannot set properties of null" error typically indicates that your JavaScript code is attempting to access or modify an element that does not exist in the DOM. This often happens when the script runs before the DOM is fully loaded or if the element's selector is incorrect.
Common Issues and Fixes:
document.getElementById()match the IDs in your HTML.Amit MohantyPosted Mar 27, 2024, 5:49 AM
You're trying to populate a textarea with the ID "section1_target_action" + [0]. However, this will result in the ID being "section1_target_action0", which might not be what you intended. Try the below code once:
Rodel BarbinPosted Mar 27, 2024, 2:08 AM
Hi Amit,
Please see code snippet below. The problem here it is not populating to section1_target_action array it return this error.
HTML:
Javascript:
var xmlhttp = new XMLHttpRequest();
//creating URL to php to retrieve data from backend.
url="getSaveDraftExemptValues.php?evaluator_id="+evaluator_id;
xmlhttp.open("GET",url,true);
xmlhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200)
{
var myObj = JSON.parse(this.responseText);
let section1_action = myObj[0].section1_action;
document.getElementById("section1_target_action" + [0]).value = section1_action;
}
}
xmlhttp.send(null);
Back end: PHP
$output = array();
$database = new Database();
$db = $database->getConnection();
$userModel = new Transaction($db);
$evaluator_id = $_GET['evaluator_id'];
$save_draft=1;
$output = $userModel->getSaveDraftEmployee($evaluator_id,$save_draft);
//Send in JSON encoded form
$result= json_encode($output,true);
echo $result;
Thank you.
Amit MohantyPosted Mar 26, 2024, 10:15 AM
Could you please share a minimal, reproducible code snippet to understand the issue? Without seeing your code, it's difficult to provide specific guidance.