Gossamer Forum
Home : Products : DBMan : Customization :

Using java scripts in dbman

Quote Reply
Using java scripts in dbman
Eliot, and others, recently advised me, on the perl forum, to keep javascript out of perl scripts. I was advised to use *.js files instead.
Not being a programmer, I was stumped at first. However, with a little experimentation I found that java scripts can be converted into .js files with no difficulty. The scripts can then be called from within an html.pl file very easily using the java script tags and src=*.js
I think many other non-programmers like me would wish to know this, as it is a simple way to add functionality to the great dbman script.

David Olley
Anglo & Foreign International Limited,
http://www.afil.co.uk
Quote Reply
Re: Using java scripts in dbman In reply to
Good suggestion...you might want to consider posting an example of how people can do this...

Regards,

Eliot Lee
Quote Reply
Re: Using java scripts in dbman In reply to
OK - here goes.

Tip for Beginners

In order to avoid possible conflicts between java script codes included within your html.pl files, it is possible to change the scripts. However, it is actually far more effective to keep java script codes out of your .pl files.
Instead, write the java script code into a .js file.
As an example, the following java script (a short, simple, but useful code) creates a button that launches the Windows Print dialogue window. It is useful to enable a viewer to print a displayed html page, or frame (a price list, or application form, maybe). This is how you would normally include it in your html:

<script language="java script">

if (window.print) {
document.write('<form> '
+ '<input type=button name=print value="Print Page" '
+ 'onClick="javascript:window.print()"></form>');
}

</script>

To create the .js file, simply copy the 5 lines of code enclosed between the opening and closing <script> tags and paste into a new window in your text editor (I use EditPlus). Then Save it as, say, "print_button.js"

Upload this file into your dbman html pages directory.

Within your html.pl file, instead of the above code, insert:

<script language="javascript" src="http://www.domain_name.com/path/to/dbman_html/print_button.js></script>

Positioning of the output would be done with normal html codes, and it may be placed in a table cell.

I am not skilled in perl or java, so if anyone out there tells me that there are exceptions to this, I will not be at all surprised! But it worked for me with a much longer java script that produces a very nice calendar.

David Olley
Anglo & Foreign International Limited,
http://www.afil.co.uk
Quote Reply
Re: Using java scripts in dbman In reply to
Uh..David,

Java and Javascript are two TOTALLY separate programming languages...not a good idea to confuse them or blend them together...

bye.

Regards,

Eliot Lee
Quote Reply
Re: Using java scripts in dbman In reply to
True, indeed.

Thanks.

I hope I did not confuse anyone. Better to leave this sort of thing to the experts.


David Olley
Anglo & Foreign International Limited,
http://www.afil.co.uk
Quote Reply
Re: Using java scripts in dbman In reply to
Hi I tried doing what you suggested, but it doesn't work. I copied the 5 lines of code into a file with the extension .js and then I inserted the link to the code into the html portion. What happened is that all of the html code below the javascript portion did not show up. what do u think could be the problem?

Reena
Quote Reply
Re: Using java scripts in dbman In reply to
Do you mean you tried using the code I posted? If so, it should work. Did you close the script call with </script> ?
Email me your html.pl file so I can take a look. My address is in the profile.

David Olley
Anglo & Foreign International Limited,
http://www.afil.co.uk