javascript document.frmName undefined, had to use doucment.forms.frmName - javascript

So our company is in the process of converting webform websites to web applications so we can implement Azure Key Vault. A lot of these applications have javascript within the aspx. In one project particularly after converting to web application and implementing the AKV I received a issue of something broken.
function UpdateSuites(strFieldIDs, strFieldNames)
{
var frm = document.frmGrid;
var all = document.all;
frm.txtfieldIds.value = strFieldIDs;
frm.txtFieldNames.value = strFieldNames;
all.lblFieldNames.innerText = strFieldNames;
}
All of sudden this line of code is throwing undefined
var frm = document.frmGrid;
I updated it to be the following
var frm = document.forms.frmGrid;
And this resolved the issue, but we want to know why did this occur all of sudden?
All we did was migrate a website to a web application.
How does this break javascript?
The .Net Framework was 4.5, and now it's 4.8 during this migration

document.querySelector("#frmGrid") or document.getElementById("frmGrid") is what you want.
Your attempts rely on elements with ids becoming global properties, which is a 20+ year old non-standard way of doing this.

Related

Making a simple ASP webpage that displays updating values from C# program

I have never used ASP.NET before and I don't quite understand how the MVC system works, but my application is much more simple than the tutorials provided.
I have a webpage in HTML, and I currently have a C# program that gets key presses from my keyboard (Making a webpage that displays key presses). Both of these work, and the C# program prints to the terminal.
I can't however, seem to connect the two, by making a web page that has data bindings so that whenever a C# class updates, it changes the HTML content without page refresh.
This would probably require learning a lot, but I'm hoping to make it with a few files (maybe a controller isn't needed since the page has no interaction?). I'm not sure how to even make a DOTNET project, as the sample one has many built-in pages and routes that I don't understand.
So basically, this is my C# program (with DLL in the same dir)
using System;
using WootingAnalogSDKNET;
// We'll also include this for the Thread.Sleep call we'll have later on
using System.Threading;
using System;
using System.IO;
using System.Net;
using System.Threading;
Console.WriteLine("Hello Analog SDK!");
// Initialise the SDK
var (noDevices, error) = WootingAnalogSDK.Initialise();
// If the number of devices is at least 0 it indicates the initialisation was successful
if (noDevices >= 0) {
Console.WriteLine($"Analog SDK Successfully initialised with {noDevices} devices!");
}
else {
Console.WriteLine($"Analog SDK failed to initialise: {error}");
System.Environment.Exit(1);
}
while (true) {
var (keys, readErr) = WootingAnalogSDK.ReadFullBuffer(20);
if (readErr == WootingAnalogResult.Ok)
{
// Go through all the keys that were read and output them
foreach (var analog in keys)
{
Console.Write($"({analog.Item1},{analog.Item2})");
}
// We want to put on the new line character only if keys have been read and output to the console
if (keys.Count > 0)
Console.WriteLine();
}
else
{
Console.WriteLine($"Read failed with {readErr}");
// We want to put more of a delay in when we get an error as we don't want to spam the log with the errors
Thread.Sleep(1000);
}
// We want to have a bit of a delay so we don't spam the console with new values
Thread.Sleep(100);
}
Thank you in advance for you help!

Javascript broken after migrating from cognos 10.2.2 to cognos 11

I have migrated the reports from Cognos 10.2.2 to Cognos "11.0.13.1 LTS" version. The java script governing the prompt page is currently broken after migrating to 11. This is working well and good on 10.2.2.
Did something change on Cognos 11 or some functions that we are using is deprecated or something similar. Any rope would be really useful in diagnosing the issue.
We also put a ticket to IBM as well to identify what is going on
We tried editing the code and formatted the code in different ways and still getting the same behavior.
var fW = (typeof getFormWarpRequest == "function" ? getFormWarpRequest() : document.forms["formWarpRequest"]);
if ( !fW || fW == undefined) { fW = ( formWarpRequest_THIS_ ? formWarpRequest_THIS_ : formWarpRequest_NS_ );}
var form = fW;
var ID=fW.elements["_oLstChoicesID"];
var SID=fW.elements["_oLstChoicesSID"];
ID.attachEvent("onclick", m_click);
function m_click()
{
for(i=0;i<fW._oLstChoicesID.length;i++)
{
fW._oLstChoicesID[i].selected=false;
fW._oLstChoicesID[i].disabled=true;
}
for(i=0;i<fW._oLstChoicesSID.length;i++)
{
fW._oLstChoicesSID[i].disabled=false;
}
}
I want the second List "SID" to be disabled when any of the elements in the ID is selected.
I think the "FormWarpRequest" stuff is a holdover from Cognos 8. It may not work in Cognos 11.0.x. You should be using cognos.Report.getReport("_THIS_"); in Cognos 10.2.2 (https://www.ibm.com/support/knowledgecenter/en/SSEP7J_10.2.2/com.ibm.swg.ba.cognos.ug_cr_rptstd.10.2.2.doc/r_prmpt_api_cognos_report.html#cognos.report). That should still work in Cognos 11.0.x, but you'll want to begin moving to the new coding style using RequireJS (see https://www.ibm.com/communities/analytics/cognos-analytics-blog/updated-javascript-samples-for-ibm-cognos-analytics-11-0-10/ and https://public.dhe.ibm.com/software/data/sw-library/cognos/mobile/scriptable_reports/index.html) and changing the Run with full interactivity property to Yes to take advantage of the new features.

LaunchDarkly Bootstrapping: (JS) Property Assignment Expected

I am setting up LaunchDarkly to control my first feature flag and its working fine from server & client side.
Now I am trying LaunchDarkly Bootstrap approach (From the below given Link) and tried like below my code, but it's not accepting the double braces and I do not know How to get flag value by using the bootstrap approach, so where I did go wrong in my code?. Could anyone please help me with an example?
Link,
https://docs.launchdarkly.com/docs/js-sdk-reference#section-bootstrapping
Initialized client with Bootstrap option as below,
client = LDClient.initialize(sdkKey, userContext.user, options = {
bootstrap: {
{{ ldclient.all_flags(userContext.user) }}
}
});
And my function to get the flag value,
isFeatureEnabled: function (featureFlag, properties) {
console.log("Before Variation");
//we shall update the custom properties into user context.
if (properties) {
for (var k in properties) {
userContext.user.custom[k] = properties[k];
}
}
//later make the identity call to update the user details.
client.identify(userContext.user, null, function () { /*rules updated*/
console.log("New user's flags available");
//validate the feature flag
var showFeature = client.variation(featureFlag);
if (!showFeature) {
window.in8.platform.showUnauthorized('');
}
console.log("after Variation");
});
}
Full disclosure, My name is John, and I am part of the support team here at LaunchDarkly. I'll be happy to help you out with this problem
Firstly, it appears you are using an older version of the bootstrapping example. The new example has a typo fix, and uses the new all_flags_state method.
I see two major issues here. There is the primary issue of how to bootstrap flag variations from the back-end to the front-end, and how to appropriately utilize LaunchDarkly when using bootstrapping. I will tackle the issue of how to bootstrap flag variations from the back-end first.
The example in LaunchDarkly's documentation utilizes templating to include the bootstrapped values to the front end. Templating is a strategy for including programmatically generated content in your static source or text files. Templating is commonly used when compiling or deploying code, or at runtime when serving content to clients. This is done to render information only available at that time in the final version.
Different templating languages behave in different ways, but generally speaking you include tokens in your source or text files which direct the template renderer to replace that token with data you supply it.
In the documentation it mentions that this example is for templating using Ruby, but the example is using Mustache rendering, and Mustache is available in many different languages. Templating is a strategy for including programmatically generated content in your static source or text files. This is commonly used when compiling or deploying code, or at runtime when serving content to clients. This is done to render information only available at that time in the final version.
The example may not work depending on which back-end language and framework you are using. According to the tags associated with your question, I feel safe to assume that you are using .NET to power your back-end, which doesn't have a prescribed templating language. There are many open source solutions out there, though.
In the following example I'm going to use https://github.com/rexm/Handlebars.Net to render the a users bootstrapped flag values into the result variable. I am going to borrow code available from the example in the handle bars repo, and from LaunchDarkly's hello-bootstrap and hello-dotnet repos, which are available here: https://github.com/launchdarkly/hello-bootstrap & https://github.com/launchdarkly/hello-dotnet
string source =
#"
<html>
<head>
<script src=""https://app.launchdarkly.com/snippet/ldclient.min.js""></script>
<script>
window.ldBootstrap={{ldBootstrap}};
window.ldClientsideId=""{{ldClientsideId}}"";
window.ldUser={{ldUser}};
</script>
</head>
<body>
<h1>LaunchDarkly server-side bootstrap example</h1>
<ul>
<li><code>normal client</code>: <span class=""normal"">initializing…</span></li>
<li><code>bootstrapped client</code>: <span class=""bootstrap"">initializing…</span></li>
</ul>
<script>
var user = window.ldUser;
console.log(`Clients initialized`);
var client = LDClient.initialize(window.ldClientsideId, user);
var bootstrapClient = LDClient.initialize(window.ldClientsideId, user, {
bootstrap: window.ldBootstrap
});
client.on('ready', handleUpdateNormalClient);
client.on('change', handleUpdateNormalClient);
bootstrapClient.on('ready', handleUpdateBootstrapClient);
bootstrapClient.on('change', handleUpdateBootstrapClient);
function handleUpdateNormalClient(){
console.log(`Normal SDK updated`);
render('.normal', client);
}
function handleUpdateBootstrapClient(){
console.log(`Bootstrapped SDK updated`);
render('.bootstrap', bootstrapClient);
}
function render(selector, targetClient) {
document.querySelector(selector).innerHTML = JSON.stringify(targetClient.allFlags(user), null, 2);
}
</script>
</body>
</html>";
var template = Handlebars.Compile(source);
Configuration ldConfig = LaunchDarkly.Client.Configuration.Default("YOUR_SDK_KEY");
LdClient client = new LdClient(ldConfig);
User user = User.WithKey("bob#example.com")
.AndFirstName("Bob")
.AndLastName("Loblaw")
.AndCustomAttribute("groups", "beta_testers");
var data = new {
ldBootstrap: JsonConvert.SerializeObject(client.AllFlagsState(user)),
ldUser = JsonConvert.SerializeObject(user),
ldClientsideId = "YOUR_CLIENT_SIDE_ID"
};
var result = template(data);
You could take this example and adapt it to render your static source code when serving the page to your users.
The second issue is how you are utilizing the SDK. I see that you are calling identify before evaluating your user every time. Each time you call identify the SDK needs to reinitialize. This means that even after bootstrapping your initial variations you will force the SDK to reinitialize by calling identify, removing all benefits of bootstrapping. As a solution, detect if your user object has changed. if it has, then call identify. Otherwise, do not call identify so that the SDK uses the cached user attributes.
If you want to dive deeper into this and provide us with some more of the source for your wrapper you can reach out to us at support#launchdarkly.com

Enable users of a WebRtc app to download webrtc logs via javascript

I've seen the following:
chrome://webrtc-internals
However I'm looking for a way to let users click a button from within the web app to either download or - preferably - POST WebRtc logs to an endpoint baked into the app. The idea is that I can enable non-technical users to share technical logs with me through the click of a UI button.
How can this be achieved?
Note: This should not be dependent on Chrome; Chromium will also be used as the app will be wrapped up in Electron.
You need to write a javascript equivalent that captures all RTCPeerConnection API calls. rtcstats.js does that but sends all data to a server. If you replace that behaviour with storing it in memory you should be good.
This is what I ended up using (replace knockout with underscore or whatever):
connectionReport.signalingState = connection.signalingState;
connectionReport.stats = [];
connection.getStats(function (stats) {
const reportCollection = stats.result();
ko.utils.arrayForEach(reportCollection, function (innerReport) {
const statReport = {};
statReport.id = innerReport.id;
statReport.type = innerReport.type;
const keys = innerReport.names();
ko.utils.arrayForEach(keys, function (reportKey) {
statReport[reportKey] = innerReport.stat(reportKey);
})
connectionReport.stats.push(statReport);
});
connectionStats.push(connectionReport);
});
UPDATE:
It appears that this getStats mechanism is soon-to-be-deprecated.
Reading through js source of chrome://webrtc-internals, I noticed that the web page is using a method called chrome.send() to send messages like chrome.send('enableEventLogRecordings');, to execute logging commands.
According to here:
chrome.send() is a private function only available to internal chrome
pages.
so the function is sandboxed which makes accessing to it not possible

Issuing MySQL queries from standalone Javascript (no, I'm not crazy, my vendor is)

Our lab recently got an Agilent Bravo pipetting robot (it precisely dispenses tiny quantities of liquid for doing rapidly doing many biology or chemistry experiments). Apparently the glue language for extending the software that controls the robot is Javascript! I know, right?
Anyway, for the robot to be useful, we have to be able to retrieve information about the samples it's handling but every example I can find for sending queries in Javascript depends on PHP and usually the assumption that the script is running in a web-browser.
Is there some way to wrap a command-line mysql or is there already some library or utility that does this? The OS we're running is Windows 7.
Wow, thanks for the quick and useful answers.
In addition, I found a platform-specific answer: http://www.velocity11.com/techdocs/helpsystem/vworks_ug/usingjavascriptinvworks.html
Long story short, VWorks (control software for Agilent's equipment) has a run() global function that does exactly that. But, the above answers are probably more useful to this site than my own is, because they are relevant to a broader range of problems, so thanks again.
"sending queries in Javascript depends on PHP"
no it doesn't.
Just send retreive data(json) using ajax, I'd use http://api.jquery.com/jQuery.ajax/.
Yes, you can use ADO with Javascript on Windows to access various data sources. Search for "jscript ado" and you will get lots of information on this, e.g.:
// path to database
var DBpath="\\\\Server\\Path\\myDB.mdb"
// set up a few object constants
var adLockReadOnly=1
var adOpenForwardOnly=0
var adCmdText=1
// create and open a new connection (MSAccess)
var cnn=new ActiveXObject("ADODB.connection")
cnn.Provider = "Microsoft.Jet.OLEDB.4.0;Data Source=" + DBpath
try
{
cnn.open
}
catch(err)
{
// could not open connection
// view details in err.Description and err.Number
return 0
}
//open a read only recordset
var rs = new ActiveXObject("ADODB.Recordset")
try
{
rs.Open("Select * from myTable", cnn, adOpenForwardOnly, adLockReadOnly)
}
catch(err)
{
// could not open recordset
return 0
}
while(!rs.EOF)
{
// do something
rs.movenext
}
rs.close
Update:
According to info here, you can develop plugins using Visual Studio/C#. Maybe that is of some use? You could write a plugin to send the data somewhere...

Categories

Resources