I'm fixing a simple user input mulptiplication table which has been littered with errors.
I'm stuck with a partucular piece of code and do not understand what it means.
When the script is run in firbug it says "TypeError: document.getElementById(...) is null"
This is the code which is attached to html:
var get = function(name){return document.getElementById("name").value;};
var set = function(name,value){document.getElementById("name").value=value;};
That simply means that there is no element with an id property of "name" in the DOM. Perhaps your code runs before the document is ready?
It looks like this code is meant to query the DOM for an element with the id of name:
var get = function(name){return document.getElementById(name).value;};
var set = function(name,value){document.getElementById(name).value=value;};
It means that the element with id = "name" is not found in document. Look in the dom if it exists.
You can also try to add this code as event handler for ready-event to check that it works ok there - as it is already said maybe you run this code before the dom is loaded.
Related
I am working on a next js project , copied some coe on code pen , it is used for a product design of an e commerce website . However i am having this problem.
TypeError: Cannot set properties of undefined (setting 'className'). What is an equalvalent of
getElementsByClassName or how can i override this eror
here is a glimse of the code
var slider = document.getElementsByClassName("sliderBlock_items");
var slides = document.getElementsByClassName("sliderBlock_items__itemPhoto");
var next = document.getElementsByClassName("sliderBlock_controls__arrowForward")[0];
var previous = document.getElementsByClassName("sliderBlock_controls__arrowBackward")[0];
var items = document.getElementsByClassName("sliderBlock_positionControls")[0];
You can use:
document.querySelector(".your_class_name").value
querySelector() can be used to select elements on a page, just pass in a CSS like selector...
Cannot set value of undefined would mean that you are trying to select HTML elements that are not on the page. This could mean your code gets run before the components get rendered
Share your full code, or add that code inside a useEffect()
I am new to this ckeditor.
So, I was trying out something very simple. I want to inline edit this p element.
<p class="h_text" >is your site working?</p>
So, I have this script
$(document).ready(function () {
CKEDITOR.disableAutoInline = true;
var elementToEdit = $("body").find("p.h_text").first();
console.log($(elementToEdit).length);
console.log($(elementToEdit).html());
$(elementToEdit).attr('contenteditable', 'true');
CKEDITOR.inline(elementToEdit);
});
When I load the page I get this error thrown from ckeditor.js
TypeError: this.$.nodeName is undefined
From the 2 console.log output, I can confirm that the elementToEdit is valid and not null.
I got this working by changing this line in script
CKEDITOR.inline(elementToEdit);
to this
$(elementToEdit).ckeditor();
To be honest, I did not quite understand why this works and the first one does not.
It would be helpful if anyone explains this.
Try this,
var elementToEdit = $("body").find("p.h_text")[0];
instead of this,
var elementToEdit = $("body").find("p.h_text").first();
I have this code that gives me an "typerror" when it's called... could somebody please give me an idea what is wrong, I can't seem to understand what is wrong with it..
document.getElementById('cblberrormsg'+curID).style.display = "block";
var res = ''+ response;
document.getElementById('cblberrormsg'+curID).innerHTML = res;
Thank you.
document.getElementById('cblberrormsg'+curID) is returning null. That means that the object with that id does not exist.
The most common reason for this is because you're trying to execute this line of code too early before that part of the page has been parsed and loaded. Your code must either be in a <script> tag that is AFTER the relevant HTML or you must use a function that waits to execute your script until the page is loaded such as this.
But, since in this case, you're constructing an id string using a variable, it also could be that curID isn't what you think it is or has gone beyond the acceptable values in your page.
Once you've made absolutely sure that this code is not being executed until AFTER the page HTML has been loaded, then I'd suggest you instrument it like this:
console.log("curID=" + curID);
console.log("document.getElementById('cblberrormsg'+curID)=" + document.getElementById('cblberrormsg'+curID);
document.getElementById('cblberrormsg'+curID).style.display = "block";
var res = ''+ response;
document.getElementById('cblberrormsg'+curID).innerHTML = res;
Then, look in your debug log when the error occurs and see what the value is for curID when the error occurs.
jfriend00 is right, the object you're referring to doesn't exist.
If the document isn't loaded yet OR for some reason you are not properly setting curID, the code you've got will go boom every time.
You can test for this by changing your code up a bit:
var foo = document.getElementById('cblberrormsg'+curID);
if(foo){
foo.style.display = "block";
// foo exists
// do whatever, yadayadayada
}
Script threw an uncaught JavaScript error:
Cannot perform action on invalid element: UIAElementNil from target.frontMostApp().mainWindow().popover().actionSheet().buttons()["Save Note"]
Code:
var target = UIATarget.localTarget();
var app = target.frontMostApp();
var window = app.mainWindow();
target.logElementTree();
UIALogger.logPass("Stick Note Save Start");
app.navigationBar().toolbar().buttons()["Plus"].tap();
app.keyboard().typeString("Ki");
window.popover().actionSheet().buttons()["Save Note"].tap();
UIALogger.logPass("StickNoteSaveEnd");
First of all, check correct hierarchy.
Then, try to use
"app.popover().actionSheet().buttons()["Save Note"].tap();"
If it does not work for you, please give some details regarding elements structure/buttons.
I think there is a bug in action sheet access from javascript. You can see my answer to a similar question here.
Bascially I think actionSheet() always returns nil to buttons and elements. It's not supposed to, but everything I've seen suggests otherwise.
MikhailV worked out a function to tap the correct button here.
I have been trying to figure out this particular problem in my developer tools, but I've had no luck thus far. I have an error on one of my js files that says
Uncaught TypeError: Cannot read property 'value' of null
The following error refers to the 1st variable of dt_version below. The particular thing is if I comment out the first line of code. I get the same error on the following variables of offload1 and offload2. The variable is a number that I am trying to get passed over. I run this function on my body when the page loads...onload=updatetotal();
function updatetotal() {
var dt_version = document.getElementById("dt_version").value-0;
var offload1 = document.getElementById("capacity_offload1").value-0;
var offload2 = document.getElementById("capacity_offload2").value-0;
var offload3 = document.getElementById("capacity_offload3").value-0;
}
If a run an if statement looking for document.getElementByID("dt_version");...it defaults to false..so its not being carried over though on the previous page, I can see its input fine with the value in it. What am I missing here guys?
This error means that the id dt_version does not exist. Check your html to make sure it is there:
var dt = document.getElementById("dt_version");
if (dt){
// do your stuff
}else {
console.log("dt does not exist")
}
Another cause for this error may be- as you are calling the javascript function on page load there is a possible chance that your control is not yet completely rendered to the page. A simple solution is just move that control to the beginning of the page. If it doesn't work then an reliable solution is, call the function inside jquery $(document).ready().