Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have got a javascript in the Scripts folder, I was kind of hopping to pass a variable to the javascrip. is it possible?
I call my script in my masterpage like this:
<script src="/Scripts/cookie.js" type="text/javascript">
and then i want to call the variable like this:
message = message + ""<umbraco:Item field="cookietextMessage" runat="server" />"<br/>";
the cookietextMessage is in the document type.
anybody knows how to do this?
Hi Mitra,
Maybe this blog post can help you solve your problem.
http://unencode.blogspot.dk/2012/08/umbracoitem-to-javascript.html
/Dennis
But can i use it like this?
<script type="text/javascript" src="/Scripts/cookie.js">
var textMessage= "<Umbraco:Item field="cookietextMessage" runat="server" />";
script>
when i use it like this the script doesn't recognice textMessage
The javascript file is NOT parsed by the .Net page renderer, so including the umbraco:item in the script file won't work.
It WILL work if you include it on your master page (I'm assuming you're using web forms rather than MVC). So if you add:
<script type="text/javascript" src="/Scripts/cookie.js"> <script type="text/javascript"> var textMessage = '<Umbraco:Item field="cookietextMessage" runat="server" />'; </script>
That should work. If you're using MVC rather than web forms, swap the Umbraco.Item code for @Umbraco.Item("cookieTextMessage") instead.
Hope that helps!
It does not work.I think because the variable is not defined in the actual javascript, so the javascript does not read it.
It's ok though, I'm going to put it in a usercontrol.
Thanks a lot anyway :)
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
How to pass a message to a javascript
I have got a javascript in the Scripts folder, I was kind of hopping to pass a variable to the javascrip. is it possible?
I call my script in my masterpage like this:
<script src="/Scripts/cookie.js" type="text/javascript">
and then i want to call the variable like this:
message = message + ""<umbraco:Item field="cookietextMessage" runat="server" />"<br/>";
the cookietextMessage is in the document type.
anybody knows how to do this?
Hi Mitra,
Maybe this blog post can help you solve your problem.
http://unencode.blogspot.dk/2012/08/umbracoitem-to-javascript.html
/Dennis
But can i use it like this?
<script type="text/javascript" src="/Scripts/cookie.js">
var textMessage= "<Umbraco:Item field="cookietextMessage" runat="server" />";
script>
when i use it like this the script doesn't recognice textMessage
Hi Mitra,
The javascript file is NOT parsed by the .Net page renderer, so including the umbraco:item in the script file won't work.
It WILL work if you include it on your master page (I'm assuming you're using web forms rather than MVC). So if you add:
That should work. If you're using MVC rather than web forms, swap the Umbraco.Item code for @Umbraco.Item("cookieTextMessage") instead.
Hope that helps!
It does not work.I think because the variable is not defined in the actual javascript, so the javascript does not read it.
It's ok though, I'm going to put it in a usercontrol.
Thanks a lot anyway :)
is working on a reply...