Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

value from the database into javascript


Go to End


2 Posts   1550 Views

Avatar
steve_nyhof

Community Member, 224 Posts

6 December 2009 at 7:28am

Edited: 06/12/2009 7:30am

public static $db = array(
'TrackingName' => 'HTMLText'
);

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new TextField('TrackingName','Tracking Code Name'));

---

How do I get this value from the database for the page I am on, and pass it to a javascript var? Maybe metadata

var trackingname = $TrackingName (I know this isn't right - this idea)

Avatar
steve_nyhof

Community Member, 224 Posts

6 December 2009 at 8:12am

Edited: 06/12/2009 8:14am

Well, not sure if this is ok or not, but it works.

var trackingname = $TrackingName works

My TrackingName field - I entered "test" and it passed it into the script!

Better yet, I added the quote around the name and that worked also... var trackingname = "$TrackingName"

Then I just entered the name of my code in the field.