Uncaught Error: Syntax error, unrecognized expression: #[object Object] - javascript

The code I am getting the error for, after doing research I can not understand why this error keeps coming up. The line of code was working before but now this is crashing my entire project.
function HomePageView_GetActiveTopicParentId(id) {
return $("#" + id).attr("egain-parent-identifier");
}
the second set of code
function HomePageController_TopicsViewChanged(id) {
sessionStorage.setItem(CURRENT_TOPIC_PARENT_ID, HomePageView_GetActiveTopicParentId(id));
sessionStorage.setItem(CURRENT_TOPIC_ID, HomePageView_GetActiveTopic(id));
$.mobile.changePage("#ViewTopicPage");
}

The problem is that id needs to be a string but it is some other type of object. Where is your HomePageController_TopicsViewChanged function being called, and what is being passed in as the id parameter?

Related

$scope.$watch can not watch some values

I'd faced an issue related to $scope.$watch. Here is my code snippet.
$scope.$watch('vm.pageData.wti.price', function(value) {
filterWatcher.setWtiPrice(value);
}
vm.pageData.wti.price has price data, like $30.00
When executed code, I got this error:
Syntax Error: Token '.00' is an unexpected token at column 4 of the
expression [$30.00] starting at [.00].
It seems the value "$30.00" inside the variable "vm.pageData.wti.price" caused this error. Is it impossible to watch the data of this kind?
add a true argument after the function, this will watch an object inside the object
$scope.$watch('vm.pageData.wti.price', function(value) {
filterWatcher.setWtiPrice(value);
}, true);

Uncaught TypeError: Illegal invocation when looping through object

I am trying to make a for loop which loops a object and should have logged the appropriate value of the instrument respectively,
but I am getting this unknown error when executing this :
gge = true;
for (var ins in instruments) {
if (gge) {
this_ = ins;
console.log(instruments[this_]);
}
};
executing this script is resulting in this error..
Uncaught TypeError: Illegal invocation
the instruments object is http://pastebin.com/tRzvpwgU
can anyone please help with solving this?? or explaining why this is happening?
I tried..
console.log(JSON.stringify(instruments[meow]));
stringing it somehow removes the error.

Uncaught TypeError: Cannot read property 'innerHTML' of null

Keep getting this error, no idea why
Uncaught TypeError: Cannot read property 'innerHTML' of null
My code is:
function write(message) {
document.getElementById('message').innerHTML += message + '<br/>';
}
function calculateCircumference (diameter) {
return diameter * 3.14;
}
write (calculateCircumference(4));
Admittedly, the error message is not exactly transparent as to its meaning (but at least you get an error - jQuery would just silently do nothing!)
What it means is that the result of document.getElementById('message') is null. Looking at the docs you will find that this happens when the element cannot be found.
The main reason for an element not being found is because it doesn't exist yet.
<script>// do something with document.getElementById('message');</script>
<div id="message"></div>
The above will FAIL because message does not exist yet. Moving the script after the div will make it work.
Side-note: 3.14 is far too inaccurate. Use Math.PI instead, it's as accurate as a number in JavaScript can be.
Seems that your code is executed before the DOM is ready
window.onload = function(){
function write(message) {
document.getElementById('message').innerHTML += message + '<br/>';
}
function calculateCircumference (diameter) {
return diameter * 3.14;
}
write (calculateCircumference(4));
}
If you have your id is set and you still get the same error, make sure you have done the opening and closing tags of your html correctly.
This error is usually caused when the element is not loaded and the js function is trying to access it.
try adding the <script> tag at the very end of the document before </body>
or check if the name of the element is mistyped.

Passing variable to function in javascript and jQuery

quick question,why this don`t work and how to fix it
$("#Button").click(function(){
count++;
var b=new Button(count);
b.render();
$("#div"+ count).dblclick(function(){
var diva=this;
$(this).append("<span id='colorchange'><input type='color' id='color' onchange='func("+diva+")' name='favcolor'></span>");
});
});
function func(diva){
alert(diva);
}
i`m getting error Uncaught SyntaxError: Unexpected identifier
You can add jquery library "http://code.jquery.com/jquery-1.9.1.js",
and Button is not recognized unless you defined it anywhere...
You can get help from "http://sideroad.secret.jp/plugins/jQueryRender/"

AngularJS: $watchCollection does not work; throws error

I've got a problem in AngularJS where $scope.$watchCollection() throws an error. I've reduced my code to the point where it's exactly the same as example code in the docs (http://docs.angularjs.org/api/ng.$rootScope.Scope#$watchCollection), and the error is still thrown:
function OverviewCtrl($scope) {
$scope.names = ['igor', 'matias', 'misko', 'james'];
$scope.dataCount = 4;
$scope.$watchCollection('names', function(newNames, oldNames) {
$scope.dataCount = newNames.length;
});
}
I get the error
'undefined' is not a function (evaluating '$scope.$watchCollection('names', function(newNames, oldNames) {
$scope.dataCount = newNames.length;
})')
I have no idea what the problem could possibly be. I'm doing exactly what the docs say, except I'm putting it in a controller, but it seems this code is intended for use in controllers. So what's the problem here?
You could also use the following syntax :
$scope.$watch('myCollection', function(value, oldValue) {
// insert awesome code here
}, true);
The true parameter tells AngularJS to "deepwatch" the value.

Categories