unable to get property 'value' of undefined or null reference IE11 - javascript

I have a code that is working fine in ie8 but in ie11 it's giving me error -"unable to get property 'value' of undefined or null reference "while debugging. I am adding just a part of function. If you notice it is working fine for other elements just on isSpanish it is failing. Any suggestions are welcome.
function callSchedule() {
document.getElementById("hideCallbackRow").style.display = "block";
document.getElementById("scheduleCallBtn").disabled = true;
var callbackDate = '';
var callbackCallTimeZone = '';
var callbackCallTime = '';
var spanish = '';
if(document.getElementById("fromDate1") && document.getElementById("requestedCallTimeZoneSelectedVal") && document.getElementById("requestedCallTimeSelectedVal")){
setCallbackValues();
callbackDate = document.getElementById("fromDate1").value;
callbackCallTimeZone = document.getElementById ("requestedCallTimeZoneSelectedVal").value;
callbackCallTime = document.getElementById("requestedCallTimeSelectedVal").value;
spanish = document.getElementById("isSpanish").value;

Related

JavaScript .startWith() function not working in IE, inside angularjs project

Hi im using Angularjs for my project, There is nationality search drop down. I want to map which is typing on Input and filter it inside nationality JSON object. This part is working fine in other browsers except IE. There is console error "Object doesn't support property or method 'startsWith'". this is my code, Can i know how to add "String.prototype.startsWith" for this issue for my code.
$scope.searchNationality = function (data) {
var output = [];
if (data != "" && data != undefined) {
$scope.ShowNationalityDropDown = true;
for (var i = 0; i < $scope.nationalityList.length; i++) {
if ($scope.nationalityList[i].content.toLowerCase().startsWith(data.toLowerCase())) {
output.push($scope.nationalityList[i]);
}
}
$scope.nationalityListSearchResults = output;
} else {
$scope.ShowNationalityDropDown = false;
$scope.nationalityListSearchResults = [];
}
};
You can try changing from .startsWith to .indexOf since it is compatible with IE for lower versions. If .indexOf returns 0 then the string is in the first position of the string that calls that function, which can be usable when you are in this kind of situation that you can't use .startsWith().
const str = "Hey this is a sample string!"
console.log(str.indexOf("Hey") === 0)
console.log(str.indexOf("sample") === 0)
$scope.searchNationality = function (data) {
var thereIsData = data != "" && data != undefined;
var output = thereIsData
? $scope.nationalityList.filter(function (nationality) {
return nationality.content.toLowerCase().indexOf(data.toLowerCase())) == 0;
})
: [];
$scope.ShowNationalityDropDown = thereIsData;
}

Jquery Uncaught TypeError on Custom function

In my code I am getting Uncaught TypeError: Cannot read property '1' of null in console but my function looks fine I don't know why its causing this error every time how ever other functions like this I prepared works totally fine
Here is working jsFiddle
Here is the part of my code
$(document).ready(function() {
var URLCheck = document.referrer;
var frameLocation = URLCheck.match(/:\/\/(.[^/]+)/)[1];
var whiteLocation = 'mywebsite.com';
if (whiteLocation == frameLocation) {
$('#adprimary').remove();
}
});
Because String.prototype.match returns null if no match was found and you're trying to access the attribute 1 of null.
Check if it's null before accessing any attributes:
var frameLocation = URLCheck.match(/:\/\/(.[^/]+)/);
if(frameLocation !== null) {
frameLocation = frameLocation[1];
}
Or the short version:
var frameLocation = (URLCheck.match(/:\/\/(.[^/]+)/) || [])[1];
Inside your code:
$(document).ready(function() {
var URLCheck = document.referrer || ''; // make sure referrer is a string
var frameLocation = URLCheck.match(/:\/\/(.[^/]+)/)[1];
if(frameLocation !== null) {
frameLocation = frameLocation[1];
}
var whiteLocation = 'mywebsite.com';
if (whiteLocation == frameLocation) {
$('#adprimary').remove();
}
});
the document.referrer may not exists;
the URLCheck.match(/:\/\/(.[^/]+)/) may be undefined

Nodelist getAttribute IE11 JavaScript Error

I am currently having an issue with the getAttribute() method.
This currently works in IE8, but in IE11 I recieve the error Object doesn't support property or method 'getAttribute'.
The same issue happens when I use hasAttribute() at the same point.
The error is thrown when you reach if(discounts[j].getAttribute("id") == discountId), and if I try to console.log the id, I get Undefined.
I did manage to get it to work in IE11 by running in compatibility mode, but that is not an option.
This is the method I am currently using below.
if(discountsXml != null && discountsXml.documentElement != null) {
var invItems = discountsXml.documentElement.getElementsByTagName("invItem");
var invItemsCounter = invItems.length;
var i = 0;
for(i=0; i<invItemsCounter; i++) {
if(invItems[i].getAttribute("id") == invItemId) {
var discounts = invItems[i].childNodes;
var discountsCounter = discounts.length;
var j = 0;
for(j=0; j<discountsCounter; j++) {
if(discounts[j].getAttribute("id") == discountId) {
discount = true;
}
}
}
}
}
You didn't actually ask a question above so I'm not sure on the best answer,
But would it be possible for you to use the id property instead of the id attribute as is generally recommended?
invItems[i].id vs invItems[i].getAttribute("id")
http://www.w3schools.com/jsref/prop_html_id.asp

Can't seem to move segment into repeating field

I have a piece of code that I'm trying to get to work on an interface. Basically we take some fields and drop into other segments. The problem seems to be that it leaves the data where it is instead of moving it to the indexed PID segment. Also the CP variable is returning 'undefined' for some reason.
var i = msg['PID']['PID.13'].length();
var homeNum;
var netNum;
var cpNum;
while(i--)
{
if (msg['PID']['PID.13'][i]['PID.13.2'].toString() == "PRN")
{
homeNum = msg['PID']['PID.13'][i]['PID.13.9'];
}
if (msg['PID']['PID.13'][i]['PID.13.2'].toString() == "NET")
{
netNum = msg['PID']['PID.13'][i]['PID.13.4'];
}
if (msg['PID']['PID.13'][i]['PID.13.2'].toString() == "CP")
{
cpNum = msg['PID']['PID.13'][i]['PID.13.9'];
}
msg['PID']['PID.13'][i] = "";
}
msg['PID']['PID.13'][0]['PID.13.1'] = homeNum;
msg['PID']['PID.13'][0]['PID.13.4'] = netNum;
msg['PID']['PID.13'][1]['PID.13.1'] = cpNum;
Sample HL7 msg I am using before transforms (from our test system, NOT live data)
It should resemble this instead:
|9999999999^^^test#test.com~99999999999~~~|
Any ideas/pointers on why it's not moving?
You are missing a toString() when you set the variables. A typical Mirth thing, because you get the E4X object back in the variable instead of the value you expected.
In addition to this, you should check the variables for undefined values before setting them on the new structure because otherwise you end up with "undefined" in the fields.
This is a working solution:
var i = msg['PID']['PID.13'].length();
var homeNum;
var netNum;
var cpNum;
while(i--)
{
if (msg['PID']['PID.13'][i]['PID.13.2'].toString() == "PRN")
{
homeNum = msg['PID']['PID.13'][i]['PID.13.9'].toString();
}
if (msg['PID']['PID.13'][i]['PID.13.2'].toString() == "NET")
{
netNum = msg['PID']['PID.13'][i]['PID.13.4'].toString();
}
if (msg['PID']['PID.13'][i]['PID.13.2'].toString() == "CP")
{
cpNum = msg['PID']['PID.13'][i]['PID.13.9'].toString();
}
msg['PID']['PID.13'][i] = "";
}
if(homeNum != null) msg['PID']['PID.13'][0]['PID.13.1'] = homeNum;
if(netNum != null) msg['PID']['PID.13'][0]['PID.13.4'] = netNum;
if(cpNum != null) msg['PID']['PID.13'][1]['PID.13.1'] = cpNum;

Javascript error while using EncryptedLocalStore

I am trying to make my first JS-based adobe air app.
But I've stuck at a point.
Here's the code which is causing the error
var RunUrl = 'http://www.lilpirate.net';
var firstRunUrl = 'http://www.netbloo.com';
var snxApp = air.EncryptedLocalStore.getItem( 'snxApp' );
var semail = snxApp.readUTFBytes( snxApp.bytesAvailable );
if( semail!='786') {
data = new air.ByteArray();
data.writeUTFBytes( '786' );
air.EncryptedLocalStore.setItem( 'snxApp', data );
var snxUrlToLoad = firstRunUrl;
}
else
var snxUrlToLoad = RunUrl;
When compiling it from adl, it throws error -
TypeError: Result of expression 'snxApp' [null] is not an object.
Help!
You are accessing properties (bytesAvailable and readUTFBytes) of snxApp without checking to make sure it exists first. If you haven't used setItem to store anything with that name yet, it will be null.
Here's an example of how it would look with an if statement:
var snxApp = ...;
var semail;
if (snxApp !== null) {
semail = snxApp.readUTFBytes( snxApp.bytesAvailable );
}
...

Categories

Resources