I have function
function someFunction(event) {
var dataP = event.currentTarget.getAttribute("some-attribute");
}
and only in Firefox I got error that "Event is undefined".
What can I do about this problem?
I changed the way of getting this attribute value like this
var dataP = document.getElementById("element-id").getAttribute("some-attribute")
and it works.
Related
I am getting this error when I run the test Cases (Jasmine):
TypeError: Undefined is not a constuctor (evaluating 'selectList.append(options)')
I am not sure why a few of my test cases are failing because of this. The tests in my browser run absolutely fine but failing locally (Maven test). (Using Jasmine, Phantom JS).
Here I have an editUser button, which when clicked hides and (update and cancel) buttons pop up which are hidden until then.
function userEditUser(id) {
var grandParent = $('#updateUser' + id).parent().parent().parent();
var updateUser = $('#updateUser' + id);
updateUser.siblings().removeClass('hideElement');
updateUser.addClass('hideElement');
var column_authority = document.getElementById('name1');
var name_list = ["A", "B", "C"];
var selectList = document.createElement('select');
selectList.setAttribute('name', 'userName');
for(var i = 0; i <name_list.length; i++){
var options = document.createElement('option');
options.text=name_list[i];
selectList.append(options);
}
column_authority.appendChild(selectList);
One of the Test Cases that is failing:
it('update button should not have a css class hideElement', function () {
$('button[name="updateUser"]').click();
expect($('button[name="updateBtn"]')).not.toHaveClass('hideElement');
});
But it is failing at this point of the function:
selectList.append(options)
I guess Phantom JS does not recognize append function. Things are working fine for me now,
all I did is changed
selectList.append(options); to
selectList.appendChild(options);
This change answered all my failing test cases.
Thank you guys very much for your interest in providing a solution for my issue.
window.onload = function () {
var console = null;
console.log(1);
}
When I run that js code,find this error
Uncaught TypeError: console is not a function
I know the Object console is Overwritten by variable ,but how can I resolve the problem, I don't want to change the variable console.
Try this.
window.onload = function () {
test_console();
}
var console = null;
function test_console() {
window.console.log(1);
}
Try this
window.console.log('something')
this work because all global object are in window;
window.console will get you the object, however, if you're using IE and you don't have the Developer Tools window open console will not return anything.
<script>
var tarih = tarih();
alert(tarih);
function tarih() {
var s=emrah;
return(s);
}
</script>
Bu fonksion neden undefined dönüyor ?
Why "undefined" returns?
The reason it returns undefined, is because of the assigment
var s = emrah
is confusing JS. So, it looks for a var name emrah and doesn't find it. That is the reason, you get undefined. Plus, if you are looking at your console, it would already have given you an error message, that
emrah is not defined
You might want to try: (If that's what you wanted)
var s = 'emrah'
You are calling the method before its defined.
Change the code to something like this.
<script>
function tarih() {
var s='emrah';
return(s);
}
var tarih = tarih();
alert(tarih);
</script>
I'm not sure why im getting the error, but i'm getting "cannot call method replace of undefined". It's happening on the the $('#wizard'+optionalArg) part, if I remove the optionalArg part it works fine. Any idea why this is happening?
function loadWizard(optionalArg)
{
optionalArg = (typeof optionalArg === "undefined") ? "" : optionalArg;
$('#wizard'+optionalArg).smartWizard({contentURL:'/welcome/form_view',
transitionEffect:'slideleft', onLeaveStep:leaveAStepCallback,onFinish:onFinishCallback, contentCache:false});
}
function call
var id = 2;
loadWizard(id);
before I send over the ID i run this
$('#all_wizards').append('<form action="#" method="POST"><div id="wizard2" class="swMain template"></div></form>');
so wizard2 should exist..
It can be:
$('#wizard'+optionalArg) //would make wizard2
there is no element in your html with this id, so calling method on undefine throw exception.
Try with null check:
function loadWizard(optionalArg)
{
var myElement=$('#wizard'+optionalArg);
if(myElement.length>0){
$('#wizard'+optionalArg).smartWizard({contentURL:'/welcome/form_view',transitionEffect:'slideleft', onLeaveStep:leaveAStepCallback,onFinish:onFinishCallback, contentCache:false});
}
}
Are you sure you have an element with
id="wizard1" (assuming optionalArg = 1)
Debug by putting a console.log to ('#wizard'+ optionalArg) and check whether the element exists? most likely the element does not exists and hence creating and error.
I'm receiving an Uncaught ReferenceError on a variable I assign in function that runs on a onblur event. Says the variable is undefined, when it is clearly defined in the function.
Error Message:
Uncaught ReferenceError:
labSectionsByGraduate is not defined
at calculateGTALabCost (AvailableFundsCosts.aspx:218)
at doCalculations (AvailableFundsCosts.aspx:269)
at HTMLInputElement.onblur (AvailableFundsCosts.aspx:685)
I tried add alert(labSectionsByGraduate) to test what was going on just after the 3rd variable(GTASemesterStipend) and that works been when I use an alert(GTALabCost) nothing happens for the alert. I guessing it has something to do with my if conditions.
function calculateGTALabCost()
{
var labSectionsbyGraduate = parseFloat(document.getElementById("cphMain_gridPTA_iTxtAmount_0").value);
var GTAlab = parseFloat(document.getElementById("cphMain_gridTLS_iTxtAmount_1").value);
var GTASemesterStipend = parseFloat(document.getElementById("cphMain_gridTLS_iTxtAmount_5").value);
if(isNaN(labSectionsbyGraduate))
{labSectionsbyGraduate = 0.00;}
if(isNaN(GTAlab))
{GTAlab = 0.00;}
if(isNaN(GTASemesterStipend))
{GTASemesterStipend = 0.00;}
var GTALabCost = parseFloat((labSectionsByGraduate / GTAlab) * GTASemesterStipend);
alert(GTALabCost);
var cell = document.getElementById("cphMain_gridPC").rows[2].cells;
cell[1].innerHTML = GTALabCost.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
}
I expect the output to change the cell of my table/grid to answer of the calculation that am trying to do.
Your line var GTALabCost = parseFloat((labSectionsByGraduate / GTAlab) * GTASemesterStipend); uses labSectionsByGraduate but you define labSectionsbyGraduate. Just a camel case error. Cheers!