Cannot set property 'value' of undefined in core.js file
-
24-06-2021 - |
Question
I understand what this error means i just can't seem to understand why does it happen.
I am using Joomla 1.7 and created a component. Now everything worked and one weird day i recieved this error when trying to submit a form. This is what i have :
<form action="index.php" method="post" name="adminForm">
..some elements...
<input type="hidden" name="option" value="<?php echo $lists['option']; ?>" />
<input type="hidden" name="task" value="<?php echo $lists['task']; ?>" />
</form>
When $lists['task']
echos exactly what it suppoused to.
Now the error is showing inside the core.js joomla file on the submitForm function, which contains :
function submitform(a) {
if (a) document.adminForm.task.value = a;
if (typeof document.adminForm.onsubmit == "function") document.adminForm.onsubmit();
typeof document.adminForm.fireEvent == "function" && document.adminForm.fireEvent("submit");
document.adminForm.submit()
}
Sorry the file is compressed, basically it's a very simple function that sets the task element to the given var and submits form.
(FYI : the a
var is the right var and everything is sent perfectly)
Now what i can't seem to understand is how come i get this error when it never happened before and i have created many forms like this inside the component exactly the same and it works fine.
Solution 3
Well the problem was as WTK suggested, there was an HTML error. Some code broke the HTML (2 table rows there were outsite a table) which caused this error.
OTHER TIPS
If an onsubmit event handler is present, that function will be called twice:
1- document.adminForm.onsubmit();
2- document.adminForm.submit(); (will also trigger onsubmit event handler).
Since I don't see that code here, I can't diagnose further. However, you may want to place a debug point (using Firebug for example) in this submitForm function as well as one in any handlers attached to the onsubmit event.
<input type="hidden" name="task" value="<?php echo $lists['task']; ?>" />
property "value" must be empty, it will assigned by joomla js
<input type="hidden" name="task" value=""/>
in www/media/system/js/core-uncompressed.js around line 22, after
if (!form) {
form = document.getElementById('adminForm');
}
add:
if (!form) {
form = document.adminForm;
}