These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Homemade Search field questions

Lextreme
Registered: May 4 2009
Posts: 12

Hi!

I'm currently working on a internal handbook for computer related problems. In this document I want a home button (to the home page), a help button (to the help page) and a search box.

Nearly everything works perfectly (thanks to this site!!!) but I still have two issues.

The program I use is Acrobat Professional 8.1.

The search box is a text box, and next to it is a "Go" button which runs the javascript:

var Searchword = this.getField("Search").value;
search.bookmarks = "true";
search.wordMatching = "MatchAllWords";
search.query(Searchword, "ActiveDoc");

It runs a query and works great! Except one thing, it always finds the value in the search box first which I just typed in, and since the searchbox is duplicated to every page, it finds it multiple times.

As you may understand, this is pretty annoying and I would like to exclude this box in the search or something. One workaround which works is to reset the Searchbox value to "Search..." before the query is executed but this is not perfect.

The other issue is simpeler (I think :p), I would like to run a javascript when someone types something in the searchbox and presses Enter instead of clicking on "Go".

Any ideas?

Thanks in advance!

My Product Information:
Acrobat Pro 8.1, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
If you embed an index into the file the search will use the index and ignore data in the form fields. Just make sure they are all empty when you create the index.

Use the "Advanced > Document Processing > Manage Embedded Index..." menu itemTo run the code when the user hits the return key, place your search script into the Format Script.
if( (event.commitKey == 2)&& !/^\s*$/.test(event.value))search.query(event.value, "ActiveDoc");

This script will run only when the user presses return after entering new data. It will not search if the user tabs or clicks out of the field and it will not search for white space (empty entries).

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Lextreme
Registered: May 4 2009
Posts: 12
Thanks! It works! Both solutions! :D

I would like to change one thing, now you need to change the data in order to repress enter and activate the search. I would like to search, everytime you press enter in the searchbox, not only after you change something...

This is because I have 2 check boxes which changes the search.wordMatching object, and it would be handy if this works without changing the data after a search. Not necessary, but handy :)


Again: Thanks in advance!
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You can't do this from events on the text box, but you could reactivate the seach from the MouseUp events on the check boxes. Make the search a document level function. Then call the function from everywhere it can be triggered.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script