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

I need to get a number a user inputs via scripting. Halp!

Explorer ,
May 16, 2019 May 16, 2019

Copy link to clipboard

Copied

var currentPageNumbers;


myDisplayDialog();


function myDisplayDialog() {


   var myLabelWidth = 70;


   var myDialog = app.dialogs.add({name:"Set Section Markers"});


   with(myDialog.dialogColumns.add()){

      with(borderPanels.add()){

         with(dialogRows.add()){

            with(dialogColumns.add()){

               staticTexts.add({staticLabel:"First Page:"});

            }

            with(dialogColumns.add()){

               currentPageNumbers = textEditboxes.add({editContents:""});


            }

         }

      }

   }


   myDialog.show();

}

I have the code above and am trying to get the number a user inputs with my `currentPageNumber` variable, but it's not working. Can I get some help with how this needs to be to work?

Thanks

TOPICS
Scripting

Views

2.8K

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
Guru ,
May 16, 2019 May 16, 2019

Copy link to clipboard

Copied

not sure because of your spelling or what you are asking but you will need to explain what you are doing. and check your spelling so we understand what you want please.

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
Explorer ,
May 16, 2019 May 16, 2019

Copy link to clipboard

Copied

I'm trying to have a dialog box open up that prompts a user to input a number. From that input, I'm trying to store the number as a variable.

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
Guide ,
May 17, 2019 May 17, 2019

Copy link to clipboard

Copied

User input is actually currentPageNumbers.editContents

So you can just create a new variable:

var     userInput = currentPageNumbers.editContents;

By the way, are you aware that you are creating a text-edit field?

Meaning that if user inputs "5", you will not get 5 as number (integer), but 5 as text (string)...

alert(userInput+5); will not display 10, but 55. Not so good is it?

So, you should change your text-edit field to a numeric entry one.

See https://www.adobe.com/content/dam/acom/en/devnet/indesign/sdk/cs6/scripting/InDesign_ScriptingGuide_...

By the way #2, this question would fit better in the InDesign Scripting forum. Maybe a mod can move it there...

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 ,
May 17, 2019 May 17, 2019

Copy link to clipboard

Copied

Moved to InDesign Scripting

-Manan

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
Explorer ,
May 17, 2019 May 17, 2019

Copy link to clipboard

Copied

LATEST

Thanks for the info!

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 ,
May 17, 2019 May 17, 2019

Copy link to clipboard

Copied

It appears you are only looking for a way to prompt an unsuspecting user for a number. There is a standard function for that!

currentPageNumbers = prompt ("", "", "Set Section Markers");

will display a basic – yet functional enough – dialog:

See https://www.indesignjs.de/extendscriptAPI/indesign-latest/#global.html#d1e3846__d1e4527

The result is null (when canceled) or a text string, so don't forget to coerce this into a number if you need to do calculations with it.

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
Advisor ,
May 17, 2019 May 17, 2019

Copy link to clipboard

Copied

Jeff,

Try this.........

var currentPageNumbers;

myDisplayDialog();

function myDisplayDialog() {

   var myLabelWidth = 70;

   var myDialog = app.dialogs.add({name:"Set Section Markers"});

   with(myDialog.dialogColumns.add()){

      with(borderPanels.add()){

         with(dialogRows.add()){

            with(dialogColumns.add()){

               staticTexts.add({staticLabel:"First Page:"});

            }

            with(dialogColumns.add()){

           currentPageNumbers = integerEditboxes.add();

            }

         }

      }

   }

   var result = myDialog.show();

    if(result == 1){

       

   myInput = currentPageNumbers.editValue;   //your variable

}

    else if (result == 2){  

    exit(); 

    }

}

    if (myInput == 0){

    alert("Error!\nNo Number was entered!");

    exit();

    }

    alert(myInput);

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