This content has been marked as final.
Show 7 replies
-
1. Re: [JS] Very simple javascript just not working - very frustrating
Bernd Alheit Sep 24, 2008 9:03 AM (in response to Skempy)Use == not = for comparing. -
2. Re: [JS] Very simple javascript just not working - very frustrating
Skempy Sep 24, 2008 9:28 AM (in response to Skempy)ARHGGGG! I knew that! And tried it!
My original script was more complicated and I suspect that something else was going wrong as well.
var myVar = 3
if (myVar == 3)
{
this.gotoNamedDest("page3")
}
if (myVar == 4)
{
this.gotoNamedDest("page4")
}
Works fine.
Thank you.
Simon -
3. Re: [JS] Very simple javascript just not working - very frustrating
try67 Sep 25, 2008 2:45 AM (in response to Skempy)BTW - you can improve your script by using this instead of what you have now:
this.gotoNamedDest("page"+myVar); -
4. Re: [JS] Very simple javascript just not working - very frustrating
Skempy Sep 25, 2008 4:34 AM (in response to Skempy)Try67
Thanks for the tweak, it does make the script simpler. Do you know how to display an error message if the Named Destination does not exist?
I have tried...
try{
this.gotoNamedDest("page"+myVar);
}
catch(e){
app.alert("Sorry, no information is currently available" ,1,0,"Destination");
}
but doesn't work.
Thank
Simon Kemp -
5. Re: [JS] Very simple javascript just not working - very frustrating
try67 Sep 25, 2008 5:15 AM (in response to Skempy)Hi Simon,
Your syntax is ok, but the problem is that gotoNamedDest doesn't create an error if you provide it an invalid destination name. In fact, it doesn't return anything at all, so you can't directly see if it was successul or not... Also, I couldn't find a way to get the list of all destinations in a document... weird.
One possible workaround I thought of is to check the page number before and after executing gotoNamedDest (this of course will not work if you are currently on the same page as the destination). So the script will look something like this:
myPage = this.pageNum;
app.gotoNamedDest("SomeValue");
if (this.pageNum==myPage) {
// We're on the same page as before.
}
A better way would be to use this.viewState, but that's only possible if you have Acrobat 7.0.5 or higher. -
6. Re: [JS] Very simple javascript just not working - very frustrating
Skempy Sep 25, 2008 5:58 AM (in response to Skempy)Try67
Thanks again, your checking page number workaround works perfectly OK for what I need.
I have one further query then I ought to start a new thread as we are getting away from the subject of the original post.
I am currently attaching javascripts to individual buttons (60 of) on one page, each javascript has one variable that changes.
Can I create a javascript at the document level which each button refers to but uses the button name to pass a variable to the main javascript. This would mean I don't have to edit each javascript attached to every button.
Thanks in anticipation.
Simon -
7. Re: [JS] Very simple javascript just not working - very frustrating
George_Johnson Sep 25, 2008 7:55 AM (in response to Skempy)You can pass the field name of the button to a document-level function like this:
//MouseUp event of button
yourFunc(event.target.name);
George



