Linking a textbox value to coinmill script for currency conversion - textbox

I got a currency exchange script from coinmill. I want to modify it to work nice in my page. I am a newbie in html/javascript programming thats why i am asking help on this one, pls.
<script src="http://coinmill.com/frame.js"></script>
<script>
var currency_round=true;
var currency_decimalSeparator='.';
var currency_thousandsSeparator=',';
var currency_thousandsSeparatorMin=3;
</script>
$199.00 (US) = <script>currency_show_conversion(199.00,"USD","GBP");</script> GBP<br>
<small>Currency data courtesy coinmill.com</small>
This scripts works fine but shows the conversion for the default value in the script. I need to replace the value ($199.00) to a value from a textbox of id "edit_1". Automatically after the user inserts the currency to exchange, the value will show in the page.
Thanks in Advance.

I am Stephen Ostermiller, and I run http://coinmill.com/. You can make this work with the JavaScript currency API from Coinmill:
Put on onchange event on the textarea
Get the value from the text area using this.value
use the currency_convert(value,from,to) method that is available in frame.js to convert it into the currency of your choice
Write the value to where you want it in the page, for example with document.getElementById('results').innerHTML
Putting it all together:
<script src="http://coinmill.com/frame.js"></script>
<script>
var currency_round=true;
var currency_decimalSeparator='.';
var currency_thousandsSeparator=',';
var currency_thousandsSeparatorMin=3;
</script>
<textarea id=edit_1 onchange="document.getElementById('results').innerHTML=currency_convert(this.value,'USD','GBP')"></textarea><br>
Converted into GBP:<div id=results></div>
<p><small>Currency data courtesy coinmill.com</small></p>
Whene I enter "273" into the textarea, I then see "Converted into GBP: 176.32" on the page.
You can test out a live example on jsfiddle: http://jsfiddle.net/wAxnq/

Related

How can we to access value of umbraco dictionary item from Javascript

Can we access Umbraco Dictionary item value from JavaScript ?
As I am using Umbraco 6.0.5
No, you can't do it out-of-the-box.
I had to do this multiple times, and the best way I came up with, is to print all dictionary items as an object when the page loads (in <head> or something). Of curse only items for the current language.
So in your source you have
<script>
var dic = {"quantity":"Quantity","totalPrice":"Total price","securePayment":"Secure payment"};
</script>
And then get is as
window.dic["quantity"]
As far as I know, you can't do it out of the box - haven't actually tried, though.
I would first create a simple rest service in my website that returns the Umbraco dictionary item using a querystring parameter as the alias value
var alias = HttpContext.Current.Request.QueryString["alias"]
if(alias != null)
{
var dictionaryItem = umbraco.GetDictionaryItem(alias)
...
}
Then call your own webservice through javascript to get the value
What I have done is declare variable in using Javascript
<script type="text/javascript">
var UmbracoDicKeyValue = '<%= kraftvaerk.umbraco.Translations.translate("Umbraco_Dic_Key", lang) %>';
</script>
And for setting value of lang variable from server side.
protected string lang = (!String.IsNullOrEmpty(umbraco.library.Session("lang")) ? umbraco.library.Session("lang") : "en-GB");
umbraco.library.setSession("lang", lang);
Now use variable UmbracoDicKeyValue in javascript code.

JQuery change event for select not working

I have tried all the options i found on the forum, but could not get it to work.
I even tried click event but that is also not getting called.
I wonder what is wrong with my code.
<script type="text/javascript">`enter code here`
$('#test.role.list').change(function(){
alert("here");
});
<div>
<form:select id="test.role.list" path="name">
<form:option value="none" label="none"/>
<form:option value="my none" label="none"/>
</form:select>
</div>
I have a list of permissions which are keys from the messageresource properties file, so the same thing i am using as id as well. The reason it is not working is correct as mentioned by the Lee. It considers the dots as different properties of the element with id "test" which is first string before dot and the next string as probably class. So i used the onchange event as
var Ele = document.geteElementByID("test.role.list");
ele.onchange = function(){
alert("here");
}
it is working fine now.
Yes the problesms are with dots in id.
You can use it as below,
$('#test\\.role\\.list').change(function(){
alert("here");
});

Accessing hyperlink in SharePoint custom list using Javascript

I have a SharePoint 2007 custom list and one of the columns in that is a "Hyper Link or Picture" field.
My requirement is, if the field URL contains year that is less than 2009, I need to set the Url to "#". As our business requirement needs all the records lesser than 2009 are considered for archieve, hence the hyper link needs to be removed.
How to read the URL for every hyper link and make it "#" if the hyper link contains 2008 using Javascript / JQuery? The custom list is added as a web part (Screenshot attached).
Your answer is well appreciated.
Thanks,
Sriram
This might help you in the right direction...
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js" ></script>
<script type="text/javascript">
var fieldName = "LinkField"; // Put the name of the column here
$(function(){
var index = $("table.ms-listviewtable")
.find("tr.ms-viewheadertr")
.find("table[DisplayName='"+ fieldName + "']")
.closest("th").index();
var rows = $("table.ms-listviewtable > tbody > tr:not('.ms-viewheadertr')");
rows.each(function(){
var link = $(this).children("td:nth-child("+ index +")").find("a");
var href = link.attr("href")
if (true){
link.attr("href", "#");
}
});
});
</script>

Google adwords conversion tracking on jquery mobile subpage

I have a subpage in a jquery mobile page where I'd like to insert att Google adwords conversion cookie. But using the traditional snippet from Adwords doesn't work. On Android it even makes the page go blank.
Anyone done this before?
You are probably loading the conversion script later on the page by doing something like this:
(function(){
var s=document.getElementsByTagName('script')[0];
var ga=document.createElement('script');
ga.type='text/javascript';
ga.async=true;
ga.src='http://www.googleadservices.com/pagead/conversion.js';
s.parentNode.insertBefore(ga,s);
})();
Or using a jQuery function to load scripts that is similar to the function above. Turns out that you can't include the conversion.js script in this manner because it uses document.write to write the img tag on the page. Because it uses document.write some browsers will remove everything from the page and replace the content with the output of document.write, which in this case is an empty gif.
You better use the default tag provided by google to mark a conversion. If you need to load it without a page refresh just open an iframe to a page that contains this tracking code.
<script type="text/javascript">
var google_conversion_id = 1234567890;
var google_conversion_language = "en_US";
var google_conversion_format = "1";
var google_conversion_color = "666666";
var google_conversion_label = "Purchase";
if (10.0) {
var google_conversion_value = 10.0
}
</script>
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<img height=1 width=1 border=0
src="http://www.googleadservices.com/pagead/conversion/1234567890/?value=10.0&label=Purchase&script=0">
</noscript>
Of course this is just an example. You should use your own code that have your unique conversiod_id.
I researched this a bit, and came across the following links:
http://www.google.com/ads/mobile/publishers/web-publishers.html
https://support.google.com/adsense/bin/answer.py?hl=en&answer=185668
So it looks like depending on the type of ad you're running, you will have to get a customized unit for mobile.
However, I am still not sure why the page would go blank. I mean, I can totally see how some ad code does that when you try to lazy-load it, but I'm not sure why it happens in your situation.

How to invoke a javascript function when the value of struts2 autocompleter changes

I am using a struts2 autocompleter tag. Now i want to invoke a javascript function when user selects some value in the drop down. I tried onChange, onSelect, onClick event but nothing works :( Please tell me your suggestions on this.
You'd use Dojo "topics".
When a selection is made the valueNotifyTopics are fired. See the autocompleter docs for details. There is an example there, shown below:
<script type="text/javascript">
dojo.event.topic.subscribe("/value", function(value, key, text, widget){
alert('inside a topic event. after value changed');
//value : selected value (like "Florida" in example above)
//key: selected key (like "FL" in example above)
//text: text typed into textbox
//widget: widget that published the topic
});
</script>
<sx:autocompleter valueNotifyTopics="/value" href="%{#ajaxTest}" />
Note that the Dojo tags have been deprecated since Struts 2.1 and will be archived in the next release.

Resources