• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
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

Copy link to clipboard

Copied

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

Views

101

Translate

Translate

Report

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

correct answers 2 Correct answers

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;

Votes

Translate

Translate
Community Expert , Oct 21, 2024 Oct 21, 2024

You can simplify it a bit:

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

Votes

Translate

Translate
Community Expert ,
Oct 21, 2024 Oct 21, 2024

Copy link to clipboard

Copied

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;

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

You can simplify it a bit:

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

Votes

Translate

Translate

Report

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