If possible, how/where would I incorporate this js(?)

Way outta my depth on this, but the world seems to have a lot of helpful JS out there.

So I’m wondering how I might incorporate something like this into my RP file:

function rand    omStr(m) {
    	var m = m || 9; s = '', r = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    	for (var i=0; i < m; i++) { s += r.charAt(Math.floor(Math.random()*r.length)); }
    	return s;
    };

or this (I’m a copy-paste-ninja):

const recipes = ['arroz', 'burrito', 'enchilada', 'sopa'];

for (let i = 0; i < recipes.length; i++) {
  const recipe = recipes[i];
  console.log(`Recipe for: ${recipe}`);
}

console.log(`\n=== Using: forEach`);

// this is pretty common so there's a `forEach` method on arrays
function printTheRecipe(recipe) {
  console.log(`Recipe for: ${recipe}`);
}
recipes.forEach(printTheRecipe);

Thanks
J

The easiest way would be to host the prototype on Axure Share and paste all that into a plugin.

The real question what do you want to do with it and how do you want to use it? Once you have the plugin setup you could call the functions with an Open Link action, but that’s not going to do much other than print some stuff to the browser console. If you want to actually pipe that data back into your prototype you’re gonna need to write some additional code.

Open External Link: javascript:void(someFunction())

Much appreciate your reply nkrisc.

(I would get fired if I used AxShare due to confidentiality constraints.)

At the simplest, most immediate level, I’d like to make 60 text fields each display a random 8-character alpha string, eg., “MREIZOEP”, “RRPNPNQL” — unlikely, but its alright if there’s an accidental duplicate (“it’s just a prototype”).

So I go to the 2 resources I know of: forum.axure, and “the internet”:

  1. on forum.axure, i can only find solutions for numerical randoms, using Math.random

  2. on “the internet”, I can only find solutions for alphanumerical randoms, and they’re all using JS(?). I’d like to learn how to lift the code I find on the internet, strip out what Axure doesn’t need, and pop it in between Axure’s brackets, [[ ? ]] – in simple-speak.

(I didnt mean to say I needed the console.log, I just left it in for “context”)

So for my text fields, I’d like to use onLoad: [[ (display a random 8-character alpha string) ]].

Does my ask make sense? I’m just looking for some guidance, best practices, or pointers to other forums, pages, resources. Happy to do the work.
-John

Thanks, that makes clearer what you’re looking to do.

If you go this route, it won’t be as easy as popping anything in Axure’s expression engine using [[ ]] apart from an Axure variable, which would be the last step.

You’ll need to do the work and set the Axure variable (or text) directly from your script. The good news is this is doable!

Here’s some some info that should help get you started.

You can access the Axure frameworks methods in your script with the $axure object, sometimes called the AxQuery object. You can select a specific widget by name like so: $axure('@widgetName'). This returns an AxQuery object which has a .text() method which can be used to set the text (note: make sure the widget has some default text to begin with).

That means you can do something like:
$axure('@MyWidget').text(randomStr());

This requires you’ve defined the randomStr function (that you have above). You can do this by adding an Open Link action on the OnPageLoad event that defines it, or search the forums for one of the JS injection widget libraries. Using the former method, it would look like:
Open External URL: javascript: function randomStr(arg) { /* ... the function body ..*/};throw new Error();

Then you could add on each of your widgets’ OnLoad event another Open Link action that looks like:
Open External URL: javascript: $axure('@[[this.name]]').text(randomStr());throw new Error();

Now I’m not 100% this specifically will work out of the box as I haven’t tested it, but this shows you the general approach. If you run into any specifics errors or problems happy to offer a hand.

Another approach, which doesn’t require JS injection, is to pull randomly from a big string. I generated a big long string of random letters on a secure password generator site, and then OnLoad each rectangle pulls an eight-character subset with a random starting point within that range. So, not great if you’re after cryptographic levels of randomness, but it is just a prototype.

Jeff

randomish.rp (86.3 KB)

Thanks NKRSC. Looks like there’s a real world learning curve with what your describing. :wink:
Much appreciated!

Thanks Jeff that’s a really great novel solve for how easy it is.