Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

I want to create a button that takes the user to a random page but within specified pages.

Explorer ,
Oct 21, 2024 Oct 21, 2024

I want to create a button that takes the user to a random page but within specified pages. For example, if I have a document that is 100 pages long, I want a button to take the user to a random page but only between pages 40-90 can this be done? If so, how?

TOPICS
Create PDFs , JavaScript , PDF , PDF forms
370
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
Oct 21, 2024 Oct 21, 2024

var page;
var num=new Date().getTime().toString();
var num2=Number(num.slice(num.length-2));
if(num2<=40)
{page=num2+41}
else if(num2>40 && num2<90)
{page=num2}
else
{page=num2-41}

this.pageNum=page-1;

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 21, 2024 Oct 21, 2024
LATEST

You can simplify it a bit:

var page = Math.floor(Math.random() * 51) + 40;
this.pageNum = page - 1;

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 21, 2024 Oct 21, 2024

var page;
var num=new Date().getTime().toString();
var num2=Number(num.slice(num.length-2));
if(num2<=40)
{page=num2+41}
else if(num2>40 && num2<90)
{page=num2}
else
{page=num2-41}

this.pageNum=page-1;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 21, 2024 Oct 21, 2024
LATEST

You can simplify it a bit:

var page = Math.floor(Math.random() * 51) + 40;
this.pageNum = page - 1;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines