Skip to main content
Known Participant
March 31, 2019
Question

Javascript so close to working...

  • March 31, 2019
  • 2 replies
  • 956 views

I found the script below on this site and I would like to get it working for me to see if it's what I'm trying to accomplish. I have it attached to an mouseUp action of a button and it pops out a window. I click to open a file and click OK and that's all it does. No opens any file. Would someone take a look at this script and show me what's wrong or what's not right? I sure would appreciate it. I just wanna see it, I feel it's so close to working. Thanks, folks.

The script:

var docType

var Dlg ={

description:

{

name: "Select File To Open",

elements:

[

{

type: "view",

elements:

[

{

item_id: "Hdr1",

name: "Select File To Open",

type: "static_text",

},

{

item_id: "Btn1",

name: "File1",

type: "radio",

group_id: "rdgp",

},

{

item_id: "Btn2",

name: "File2",

type: "radio",

group_id: "rdgp",

},

{

item_id: "Btn3",

name: "File3",

type: "radio",

group_id: "rdgp",

},

{

item_id: "Btn4",

name: "File4",

type: "radio",

group_id: "rdgp",

}

]

},

{

type: "ok_cancel",

ok_name: "Open"

},

]

}

};

commit:function (dialog) { // called when OK pressed

    var results = dialog.store();

    if (results["Btn1"]) docType = 1;

    else if (results["Btn2"]) docType = 2;

    else if (results["Btn3"]) docType = 3;

    else if (results["Btn4"]) docType = 4;

  }

app.execDialog(Dlg);

if(docType==1){

  app.openDoc("File1", this);

}

else if(docType==2){

  app.openDoc("File2", this);

}

else if(docType==3){

  app.openDoc("File3", this);

}

else if(docType==4){

  app.openDoc("File4", this);

}

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
March 31, 2019

You have to add ".pdf" to the file-name.

pdfUser1Author
Known Participant
March 31, 2019

I added the .pdf to the file name. It still doesn't open any of the files. Is there anything else, something I'm missing? This aspect of creating pdfs is very new to me. I hope to catch on with a bit more practice. All the pdf files are in the same folder on my desktop. This is the script thus far...

var docType

var Dlg ={

description:

{

name: "Select File To Open",

elements:

[

{

type: "view",

elements:

[

{

item_id: "Hdr1",

name: "Select File To Open",

type: "static_text",

},

{

item_id: "Btn1",

name: "File1",

type: "radio",

group_id: "rdgp",

},

{

item_id: "Btn2",

name: "File2",

type: "radio",

group_id: "rdgp",

},

{

item_id: "Btn3",

name: "File3",

type: "radio",

group_id: "rdgp",

},

{

item_id: "Btn4",

name: "File4",

type: "radio",

group_id: "rdgp",

}

]

},

{

type: "ok_cancel",

ok_name: "Open"

},

]

}

};

commit:function (dialog) { // called when OK pressed

    var results = dialog.store();

    if (results["Btn1"]) docType = 1;

    else if (results["Btn2"]) docType = 2;

    else if (results["Btn3"]) docType = 3;

    else if (results["Btn4"]) docType = 4;

  }

app.execDialog(Dlg);

if(docType==1){

  app.openDoc("TeBlank.pdf", this);

}

else if(docType==2){

  app.openDoc("instrs.pdf", this);

}

else if(docType==3){

  app.openDoc("schA.pdf", this);

}

else if(docType==4){

  app.openDoc("schB.pdf", this);

}

try67
Community Expert
Community Expert
March 31, 2019

What exactly happens when you run the code? Are there any error messages?

Legend
March 31, 2019

To start with, use a full file DIPath in openDoc. Then, what does it say in console?