Retrieve multi selected value using Get and Javascript - javascript

I'm trying to read in values from a multi-select via get and javascript.
Here's an example of the string and values i'm trying to retrieve:
?q=y&deg[]=Graduate+Certificate&deg[]=Graduate+Degree
My code works with URLSearchParams in all browsers except late MS IE and early MS EDGE browsers.
Can someone suggest a way to read two separate values for deg[] without using a polyfill library?

Related

How to clear chrome performance entries or bypass the limit on their number?

I use Google Chrome to analyze the performance of some webpage that using Javascript dynamically load scripts and other resources.
I use the performance.getEntries() method, but I noticed that Chrome records only the first 150 resources. I could not find any way to get more entries, or to remove old entries.
I saw that the performance object has methods like clearMeasures or clearMarks, but I failed to use them for removing entries.
So my questions are:
Is it possible to get more than 150 performance entries? If possible - how?
Is it possible to clear the entries (for example, after reading the data of some entry, to remove it)? If possible - how?
You can try
performance.webkitSetResourceTimingBufferSize(your_number);
For what it's worth, in Firefox, you can use
performance.setResourceTimingBufferSize(your_number);
For full list of browsers and their support for window.performance, see http://compatibility.shwups-cms.ch/en/home?&property=performance
Instead of using performance.getEntries(), use performance.getEnteriesByType('resource') After measuring the timing with performance.getEnteriesByType('resource'), call performance.clearResourceTimings() right away. It will empty the buffer.
function measureTiming()
{
var resourceTiming = performance.getEnteriesByType('resource');
performance.clearResourceTimings();
}

Javascript - Retrieve OS Date formatting

Hmmm... Okay so I've been searching the web for 2 days now without any luck. I've seen a lot of answers on how to format a javascript date for example new Date().toString("yyyy-MM-dd")... Which would return something like 2013-04-05.
This is absolutely not the problem.
What I want, is the possibility to set the format in which my OS displays dates, then retrieve that specific format and display it in the browser.
For example, let's say I changed the format of the date in my OS to MM-yyyy/dd (this is for arguement sakes, whether that would work or not is irrelevant)). Then I'd expect to see 04-2013/05 in my OS, right? Next I want to retrieve this specific format in my browser via Javascript so that I can use this to format my dates throughout my webpage.
If this is lunacy and cannot be done, please tell me, as I've got a headache from searching.
Also, if you say use someDateObject.toLocaleDateString() without explaining exactly why .toLocaleDateString would work, I'm going to ignore it, because I've tried setting my date-format in my OS to numerous formats and every single time I use .toLocaleDateString(), I receive the same format: dd/MM/yyyy
first attribute of .toLocaleDateString method locale(s) used.
current locale you can obtain through navigator.language (in firefox or chrome) parameter.
in IE you can obtain navigator.browserLanguage or navigator.systemLanguage
in browsers other than IE it is impossible to obtain system language this way
after this you can call new Date.toLocaleString(navigator.language||navigator.browserLanguage) and it will be formated correctly depending on browser language

Rally App SDK 2.0: Hardcoded data values for rallymultiobjectpicker

Is it possible to input hardcoded values for a rallymultiobjectpicker? I have tried using the same method as a rallycombobox, but it does not seem to work. Is the rallymultiobjectpicker limited to getting values from a modelType? Is there any way to get values from a field on a artifact? Or is it strictly for objects? I suppose the alternative would be to use a rallycombobox with the multiSelect set to "true". However, there are no physical checkboxes, and the text field can become very crowded if there are many options selected.
Using hardcoded values for rallymultiobjectpicker is not currently supported, but that option will be available in a future version of the SDK.

How to Replicate XMLHttpRequest For JSON

New to JSON, just trying to get my feet wet.
I know how to do this with XML via javascript, but am trying to learn how to handle JSON objects so I can switch over.
Basically I want to search through all "permalink" tags in the following JSON object and, when I find the right one, save its corresponding "title" and "id" tags to javascript variables:
http://api.soundcloud.com/users/goldenstatewarriors/tracks.json?client_id=02db8e29aa2fb5bf590f478b73137c67
Can this be done with only javascript (no PHP)? The main issue I'm facing is simply grabbing the text from the page and converting it to a json object.
You need to use a JSON parser in order to transform the JSON string into an object you can handle natively in JavaScript. Recent browsers have this functionality built in as JSON.parse(), but obviously this will not work in older browsers (we're talking very old browsers here).
A solution to that problem is to use the JSON parsing library available here. If native browser support is detected, it simply uses that, otherwise it has a JavaScript implementation to achieve the same result. The file you'll need is json2.js - simply include that as you would any other library and away you go!
An example of the code would be:
var dataObject = JSON.parse(jsonData);
As a side note, XMLHttpRequest is somewhat of a misnomer these days. It is simply a mechanism for making HTTP requests and retrieving the data returned, it doesn't have to be XML. It can be plain text, (non X)HTML, JSON, anything. In fact, I don't think I've seen anything in the wild return actual XML data for an XMLHttpRequest in a very long time.

How to pass array of data from one webpage to the other?

i'm trying to send three arrays of data from one .js file which is used by first webpage to the other .js file which is used by the second webpage.
the data in the first webpage is dynamically built so those three arrays are to be sent to the next webpage.
can anyone suggest some javascript code or tutorial.
please help...............
Thank you Guys. . . . ..
I'd suggest using the JSON data format. JSON is like XML except a lot easier to parse through. Some great examples can be found on Jquery's page:
http://api.jquery.com/jQuery.getJSON/
Everything you need to read the JSON feed can be found on jQuery. If you need to know how to structure a JSON feed you can read about it here:
http://www.json.org/js.html
This is really tough to do with strictly javascript and html. Here are some options:
You could store the array in a hidden form variable and post it to the destination page
If the dataset is small enough (< 4K), then you can store it in a cookie across requests.
If you are only using the most modern browsers (read: HTML5), you can use localstorage
You could encode the data and pass it in the url
In general, though, these are mostly hacks. Usually this kind of work is augmented by some type of server-side processing (perl, php, asp.net, etc) in which you have available some kind of storage across requests (i.e. Session in asp.net).
You could use the Web Storage API, and include a polyfill to port the functionality for older browsers:
http://code.google.com/p/sessionstorage/
https://gist.github.com/350433
Both of these use window.name to provide a session-like state. This may or may not be secure enough for your needs.
From there, you can use the following code for all browsers:
// Store on previous page
sessionStorage.setItem("yourArray", JSON.stringify(yourArray));
// Restore on following page
var yourArray = JSON.parse(sessionStorage.getItem("yourArray"));
EDIT: Older browsers may need the following for the above code sample. This is so the array can be serialized to a string, since sessionStorage only supports string key-value pairs:
https://github.com/douglascrockford/JSON-js
Check out jQuery.data() and friends. Cf.: http://api.jquery.com/category/data/
You may use cookie for that purpose.

Categories