Forum OpenACS Q&A: How to insert JavaScript or .js file into ADP

Hi,
  I want to insert a java script or to put script tag into the adp file for some validations. plz help me out how to achieve this.

With Regards

Venu Madhav Deevi.

Collapse
Posted by Matthew Geddert on
what type of validations? In most cases it would be a lot easier (and cleaner and more browser independent) to do this via the "-validate" flag in ad_form. If you are talking about server side java then aolserver is probably not your best bet.
Collapse
Posted by Mark Aufflick on
I love client side JavaScript - I once wrote almost an entire shooping cart system with it - but I agree with Matthew that ad_form is your friend.

It's not as funky as doing real-time JavaScript/DHTML validating and alerting, but unless you REALLY need it, then use ad_form - it rocks(tm).

But to answer your question - anything that is not an adp tag just gets pumped out in the html output - so just use client side script tags like you normally would in an html file.

Collapse
Posted by Robert Locke on
You can also take advantage of the "header_stuff" property that is included with the default master template.  This will ensure your JavaScript is included in the <head></head> section.

Assuming you haven't removed it from your master template, just do this in your adp file:
    <property name=header_stuff>
      <script language="javascript">
      ...
      </script>
    </property>

You can also use this to include style sheets, etc.

I think that should work, though I haven't tried.

Collapse
Posted by Alfred Werner on
If you look at the page admin/entry-edit.tcl in the lars-blogger, you'll see an example of how to embed javascript validation in a form:: item.

Specifically:

element create entry entry_date -label "Entry date" -datatype text \
        -help_text "If you set this to something other than today's date, you must use this form to publish your entry, otherwise the entry date will be set to the date you publish the item." \
        -after_html {(<a href="javascript:setEntryDateToToday()">Set to today</a>)}