I have multiple forms that will be using the same bit of javascript code.
I'd like to keep the javascript code in only one place.
Is there a way that I can have this common javascript code in one file and have that file included in each of the multiple different forms?
I'd like to keep the javascript code in only one place.
Is there a way that I can have this common javascript code in one file and have that file included in each of the multiple different forms?
Hi,
Yes, by adding it to a file and uploading it to the server and including a reference to the file in your forms code.
I'm planning to have some solution to this issue and others by the new version.
Regards,
Max
Yes, by adding it to a file and uploading it to the server and including a reference to the file in your forms code.
I'm planning to have some solution to this issue and others by the new version.
Regards,
Max
Thanks.
What's the best way for "including a reference to the file in your forms code."?
What's the best way for "including a reference to the file in your forms code."?
OK.
I've taken the javascript code from the Form Javascript section and put it into a file called "myjs.js." I've uploaded this file onto the server at /media/system/js/myjs.js
In the <head> of my HTML document, I have the line,
<script src="/media/system/js/myjs.js" type="text/javascript">
I can access the js code directly when I go to http://www.mysite.com/media/system/js/myjs.js
BUT, when I access my form directly, the first js function call is 'not found'.
What am I missing?
I've taken the javascript code from the Form Javascript section and put it into a file called "myjs.js." I've uploaded this file onto the server at /media/system/js/myjs.js
In the <head> of my HTML document, I have the line,
<script src="/media/system/js/myjs.js" type="text/javascript">
I can access the js code directly when I go to http://www.mysite.com/media/system/js/myjs.js
BUT, when I access my form directly, the first js function call is 'not found'.
What am I missing?
Hi edog5948 ,
No idea without seeing the script.
A better way of loading it might be to use the Joomla! syntax.
Bob
No idea without seeing the script.
A better way of loading it might be to use the Joomla! syntax.
<?php
if ( !$mainframe->isSite() ) { return; }
$doc =& JFactory::getDocument();
$doc->addScript(JURI::base().'media/system/js/myjs.js');
?>
Bob
Hi edog5948,
Including your script as I suggested works OK here. I added this to the Form HTML (using a different location for the script):
Bob
PS The script throws some initialisation errors but is found OK.
Including your script as I suggested works OK here. I added this to the Form HTML (using a different location for the script):
<?php
if ( !$mainframe->isSite() ) { return; }
$doc =& JFactory::getDocument();
$doc->addScript(JURI::base().'components/com_chronocontact/includes/test_form_89/EmbellishmentSelection.js');
?>
Bob
PS The script throws some initialisation errors but is found OK.
OK. I think I got it!
I had referenced the article http://docs.joomla.org/Adding_JavaScript in order to include the myjs.js script.
The article uses the code
To get the code to work, I used
I was able to keep the include in the template HTML head section, too.
Thanks for your help.
I had referenced the article http://docs.joomla.org/Adding_JavaScript in order to include the myjs.js script.
The article uses the code
<?php
$document = &JFactory::getDocument();
$document->addScript( '/media/system/js/sample.js' );
?>
To get the code to work, I used
<?php
if ( !$mainframe->isSite() ) { return; }
$doc =& JFactory::getDocument();
$doc->addScript(JURI::base().'media/system/js/myjs.js');
?>
I was able to keep the include in the template HTML head section, too.
Thanks for your help.
Hi edog5948,
The two snippets are more or less the same.
[list]The isSite line is needed in ChronoForms to work around a problem with the way it evaluates code when the from is saved.
I use $doc just because it's less to type than $document.
I also use JURI::base(). to make sure that the URL is full and unambigous. [/list]
Bob
The two snippets are more or less the same.
[list]
Bob
This topic is locked and no more replies can be posted.