Skip to main content
higgsyd
Inspiring
November 6, 2016
Question

Do I really need seven copies of this code?

  • November 6, 2016
  • 1 reply
  • 610 views

http://v27.ancestry.higgsy.co.uk/

On the above page I have seven buttons.  When you hover over any of them the text changes to white and the user is directed to the appropriate page.  A simple implementation of a rollover image.

You can see the javascript if you use View Page Source and then click the myscript.js link on line 6

Each img has an ID allocated to it which links to the code which, when the button is hovered over, replaces the image with the over image with the white text, then puts the old image back when the hover is out.

But I have found I must customise the code for each button.  Specifically, I have to change the names of the images, variable names and the name of the selector targetting each button.  So I end up with seven copies of the same code!  Can it perhaps be changed to a function which accepts these changes as parameters?

many thanks in anticipation

David

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
November 6, 2016

This forum is about JS in PDF files, not web-pages.

higgsyd
higgsydAuthor
Inspiring
November 8, 2016

How does JS (assuming you mean javascript) run inside a PDF document?  I've only been aware of using it in my web pages.  If I have really posted this question in the wrong forum can you say which one I should have used? Thanks, David

try67
Community Expert
Community Expert
November 8, 2016

JS is used in many environments, the most known of which is indeed in web-pages, but certainly not the only one.

You can try StackOverflow, for example.