How to Parameterize the values in ajax TruClient scripts - javascript

This is the scenario -
There is a search criterion giving me 100 search results (100 Links).
I want the virtual users to click on any of those links ramdomly.
Can you please help me how manage this situation?

Perhaps this is useful to you? http://h30499.www3.hp.com/t5/LoadRunner-Support-Forum/Ajax-True-Client-parameterization-problem/td-p/5607543#.UDxLONYaNN9

Your path is through correlating the links into an array, picking a random offset into the array and then a web_url to head to the link in question....

Have a look at the help for the functions
web_reg_save_param()
web_reg_save_param_ex()
and especially the "Ord=All"/"Ordinal=All" parts in the help.
Then when you have captured the relevant data into an array you can use
lr_paramarr_random("TheArrayName");
to get a random value from the array.

The answer depends on whether or not every listbox element is a valid selection. If the first element of the listbox is instructional ("Please select...", etc.), you need a snippet of code:
Option 1: (when a “Please select” is present)
In the step's 'Arguments' section, Set Ordinal to:
var objectIndex = Math.floor((object.length-1)*Math.random())+2;
objectIndex;
Option 2: (when a “Please select” is not present)
In the step's 'Arguments' section, Set Ordinal to “0”.

Generate a random number in runtime and put that variable in the Ord= parameter. E.g.
a = Rand(1,100)
lr_save_param("{myrandval}",a);
Web_custome_request("",
"",
"",
"Ord={myrandval}",
LAST);

Related

D3 V4 Tree Search and Highlight

So, I really love this example from Jake Zieve shown here: https://bl.ocks.org/jjzieve/a743242f46321491a950
Basically, on search for a term, the path to that node is highlighted. I would like to accomplish something similar but with the following caveats:
I would like to stay in D3 v4.
I'm concerned about cases where the path doesn't clear out on next node pick OR what happens when there are two nodes of the same
name (I would ideally like to highlight all paths)
I would like to AVOID using JQuery
Given a set search term (assume you're already getting the string from somewhere) I know I need to make use of the following lines specifically (you can see my stream of consciousness in the comments) but I'm just not quite sure where to start.
// Returns array of link objects between nodes.
var links1 = root.descendants().slice(1); //slice to get rid of company.
console.log(links1); //okay, this one is nice because it gives a depth number, this describes the actual link info, including the value, which I am setting link width on.
var links2 = root.links(); // to get objects with source and target properties. From here, I can pull in the parent name from a selected target, then iterate again back up until I get to source. Problem: what if I have TWO of the same named nodes???
console.log(links2);
Thoughts on this? I'll keep trying on my own, but I keep hitting roadblocks. My code can be found here: https://jsfiddle.net/KateJean/7o3suadx/
[UPDATE]
I was able to add a filter to the links2 to call back a specific entry. See
For example:
var searchTerm = "UX Designer"
var match = links2.filter(el => el.target.data.name === searchTerm); //full entry
console.log(match);
This single entry gives me all associated info, including the full list of all points back up to "COMPANY"
So, I can GET the data. I think the best way to accomplish what I want is to somehow add a class to each of these elements and then style on that "active" class.
Thank you!

jquery UI autocomplete alphabetical ordering

Please see the following default example
http://jqueryui.com/autocomplete/ (default functionality)
When you type Scala and Schema those results are almost all the way down to the bottom although I would expect them to be first as they both start by S.
I think the reason is that it starts from the top of the list down checking to see if there are any Ss (Actionscript is the first entry in availableTags) and there is no default filtering.
If i was going to use something like cities and I limit the results to 10 and type "S" the first 10 results would not be cities that start by S but whatever contains s and is first in the list.
Is there a way around this ?
Sample fiddle here
Question2: How can the current entry get highlighted on the displayed results?
You could use the jquery plugin selectize.js.
This is how you could do it : http://plnkr.co/edit/1zmretjQGXeVnh74IMRj
As you can see by typing "sc", scala and scheme come first, and are highlighted.

How do I iterate over a hash in JS and return all matching results?

I have the following piece of JS code within a function that responds to the user pressing enter (not displayed). The part of the code I am concerned with is shown:
$.each(cityhash,function(key,value){
if(value['city']== user_input) {
$('#city').empty().append(value['city']);
$('#state').empty().append(value['city']);
}
I have the following hash:
cityhash = [{"address":"07288 Albertha Station","city":"Littelside","state":"Missouri"},{"address":"0615 Mervin Rapid","city":"Tessmouth","state":"South Carolina"},{"address":"779 Elody Lock","city":"Littelside","state":"New Mexico"}]
As you can see, the city of Littelside appears twice in the hash. My problem is the above $.each function, only displays 1 of the 2 Littlesides. I would like to show all matches in the hash, not just 1 match.
How can I correct my code to return all matching cities rather than just showing one city?
Thank you in advance
You need to get rid of the empty() calls. You are clearing out #city/#state on each match.
$('#city').append(value['city']);
$('#state').append(value['state']);
Also, you probably want to append the state name and not the city name to the #state element

How to append string to the url and then make url show the string?

Javascript = looked through Google and Stack Overflow -I am still lost as I am still new in programming and everything else. I have some questions that I need to know
so far, I have this below:
var getUrladdress = window.location.href; //get current url address
var sortbydiscount = "?sortby";
var discount = ["20","30","50","70"];
What I wanted to know how to do is:
append string from discount array (I have tried to use append() but it doesn't work :(
then compare the discount array against percentDiscount (still being worked on in other question)
sort the items (final one) to display all items under 20%, 30% etc group.
Could you please give me insight/guide me on how to append string from discount array and then have the url show that "http://www.xxx.com?sortby30" in live address bar?
Then could it be possible to compare array against percentDiscount?
Many thank yous in advance.
EDITED:: #3 - I wanted to have sale items categorized in different discount group: i.e. if 20%, then all items which are on sale for 20% should be only displayed on the page.
You really should get a good book on JavaScript and learn from that if you are so unsure about core language features. That said:
You are confusing appending an HTML element using jQuery (just one of the web application libraries or "frameworks" available for JavaScript) with appending one string to another (concatenating strings). The plus operator can be used to concatenate strings:
getUrladdress = getUrladdress + sortbydiscount;
To check to see if a particular item is in an array, you can use the .indexOf method of the array. Because the method was added only in ES5 (the latest version of the ECMAScript/JavaScript specification), the documentation I have linked to includes contains some compatibility code to use to get this to work on Internet Explorer.
if(discount.indexOf(percentdiscount) != -1) {
// found
} else {
// not found
}
I'm not sure what you mean by that one; perhaps you can clarify exactly what you are trying to do? Show a list of items under each discount percentage on the web page?

jQuery "Autocomplete" plugin is messing up the order of my data

I'm using Jorn Zaefferer's Autocomplete plugin on a couple of different pages. In both instances, the order of displayed strings is a little bit messed up.
Example 1: array of strings: basically they are in alphabetical order except for General Knowledge which has been pushed to the top:
General Knowledge,Art and Design,Business Studies,Citizenship,Design and Technology,English,Geography,History,ICT,Mathematics,MFL French,MFL German,MFL Spanish,Music,Physical Education,PSHE,Religious Education,Science,Something Else
Displayed strings:
General Knowledge,Geography,Art and Design,Business Studies,Citizenship,Design and Technology,English,History,ICT,Mathematics,MFL French,MFL German,MFL Spanish,Music,Physical Education,PSHE,Religious Education,Science,Something Else
Note that Geography has been pushed to be the second item, after General Knowledge. The rest are all fine.
Example 2: array of strings: as above but with Cross-curricular instead of General Knowledge.
Cross-curricular,Art and Design,Business Studies,Citizenship,Design and Technology,English,Geography,History,ICT,Mathematics,MFL French,MFL German,MFL Spanish,Music,Physical Education,PSHE,Religious Education,Science,Something Else
Displayed strings:
Cross-curricular,Citizenship,Art and Design,Business Studies,Design and Technology,English,Geography,History,ICT,Mathematics,MFL French,MFL German,MFL Spanish,Music,Physical Education,PSHE,Religious Education,Science,Something Else
Here, Citizenship has been pushed to the number 2 position.
I've experimented a little, and it seems like there's a bug saying "put things that start with the same letter as the first item after the first item and leave the rest alone". Kind of mystifying. I've tried a bit of debugging by triggering alerts inside the autocomplete plugin code but everywhere i can see, it's using the correct order. it seems to be just when its rendered out that it goes wrong.
Any ideas anyone?
max
EDIT - reply to Clint
Thanks for pointing me at the relevant bit of code btw. To make diagnosis simpler i changed the array of values to ["carrot", "apple", "cherry"], which autocomplete re-orders to ["carrot", "cherry", "apple"].
Here's the array that it generates for stMatchSets:
stMatchSets = ({'':[#1={value:"carrot", data:["carrot"], result:"carrot"}, #3={value:"apple", data:["apple"], result:"apple"}, #2={value:"cherry", data:["cherry"], result:"cherry"}], c:[#1#, #2#], a:[#3#]})
So, it's collecting the first letters together into a map, which makes sense as a first-pass matching strategy. What i'd like it to do though, is to use the given array of values, rather than the map, when it comes to populating the displayed list. I can't quite get my head around what's going on with the cache inside the guts of the code (i'm not very experienced with javascript).
SOLVED - i fixed this by hacking the javascript in the plugin.
On line 549 (or 565) we return a variable csub which is an object holding the matching data. Before it's returned, I reorder this so that the order matches the original array of value we were given, ie that we used to build the index in the first place, which i had put into another variable:
csub = csub.sort(function(a,b){ return originalData.indexOf(a.value) > originalData.indexOf(b.value); })
hacky but it works. Personally i think that this behaviour (possibly coded more cleanly) should be the default behaviour of the plugin: ie, the order of results should match the original passed array of possible values. That way the user can sort their array alphabetically if they want (which is trivial) to get the results in alphabetical order, or they can preserve their own 'custom' order.
What I did instead of your solution was to add
if (!q && data[q]){return data[q];}
just above
var csub = [];
found in line ~535.
What this does, if I understood correctly, is to fetch the cached data for when the input is empty, specified in line ~472: stMatchSets[""] = []. Assuming that the cached data for when the input is empty are the first data you provided to begin with, then its all good.
I'm not sure about this autocomplete plugin in particular, but are you sure it's not just trying to give you the best match possible? My autocomplete plugin does some heuristics and does reordering of that nature.
Which brings me to my other answer: there are a million jQuery autocomplete plugins out there. If this one doesn't satisfy you, I'm sure there is another that will.
edit:
In fact, I'm completely certain that's what it's doing. Take a look around line 474:
// loop through the array and create a lookup structure
for ( var i = 0, ol = options.data.length; i < ol; i++ ) {
/* some code */
var firstChar = value.charAt(0).toLowerCase();
// if no lookup array for this character exists, look it up now
if( !stMatchSets[firstChar] )
and so on. So, it's a feature.

Categories