21287 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1181 Views |
-
get file upload url for passing to js

25 October 2010 at 12:15pm
So following the execellent advice from my last thread i created some variables and passed them to some js.
I now need to pass the url of a file upload to the js.$fields->addFieldToTab("Root.Content.Embed", new FileIFrameField('GPSXML', 'Upload and Attach Document'));
public function init() {
parent::init();
Requirements::themedCSS("layout");
Requirements::themedCSS("typography");
Requirements::themedCSS("form");
Requirements::javascriptTemplate('mysite/javascript/maps.js', array(
'GPSXML' => $this->GPSXML.URL
));
}This doesnt seem to pass anything over to the js the alert box for $GPSXML just shows blank. I'm guessing i need to parse out the url as a string? any ideas?
thx guys
-
Re: get file upload url for passing to js

5 November 2010 at 3:46am Last edited: 5 November 2010 3:46am
Hi,
I had the same problem as you. By inspecting the Requirements::javascriptTemplate() method I found that you do need to encapsulate the replaceable variable name with quotes. Due to the way the variable is replaced, I would also recommend referencing it only once, and assigning it to a 'real' javascript variable, like so:
PHP:
Requirements::javascriptTemplate('script.js', array(
"vimeoID" => $this->vimeoID()
));script.js:
var vimeoID = '$vimeoID';
The Requirements::javascriptTemplate() method is a little used and little documented feature, but a handy one nonetheless. I hope this helps those trying to use it in the future...
-
Re: get file upload url for passing to js

7 November 2010 at 4:43pm Last edited: 7 November 2010 4:52pm
this worked for getting the value of vimeoID because it was just a text field. Here i want to pass the url of the filefieldupload.
it actually works fine if i create a text field and have the user manually enter the url but it would be much better if i could get the url straight from the file upload.
thanks heaps for all your help so far.
| 1181 Views | ||
|
Page:
1
|
Go to Top |


