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.

General Questions /

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

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

value from the database into javascript


Reply


2 Posts   1184 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.