I am creating an imacros script to select a random option inside an html select element.
Like this:
mcr +="TAG POS=1 TYPE=SELECT ... CONTENT=#"+opcionAleatoria(12)+ '\n';
Where opcionAleatoria() is a function to grab a random number:
And total is the total amount of options inside that select.
function opcionAleatoria(total) {
return Math.floor(Math.random() * total) + 1;
}
I want to be able now to pass the total (amout of options in select) as a parameter to the function.
Why?
Two reasons:
I tried passing document.form.select_id.options.length, but it won't work since in imacros document is not defined.
Do you have any ideas on how I may approach the case?
Try to modify your expression like so:
var total = window.document.forms[0].select_id.options.length;
If the suggested above way doesn't work, here's more reliable one:
iimPlay("CODE:TAG POS=1 TYPE=SELECT ... EXTRACT=TXTALL");
var total = iimGetExtract().split("[OPTION]").length;
(I suppose that you use 'iMacros for Firefox' and its Scripting Interface.)