Accessing hyperlink in SharePoint custom list using Javascript - sharepoint-2007

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>

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.

Linking a textbox value to coinmill script for currency conversion

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/

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.

report viewer web part in sharepoint (not the report viewer control) size issue

I am using SSRS in sharepoint integrated mode. When I view my reports using report viewer webpart, I often get scrollbars and it looks terrible. I couldn't find a solution for that other than sizing the report viewer webpart but as time goes on my report will grow and I do not want to do this again and again.
Any ideas how to autosize this..etc?
Thanks,
Add a Content editor webpart to the page and use the following jQuery-code:
<script type="text/javascript" src="http://yourSiteURl/_layouts/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
function RapportIframeComplete() {
if (RapportIframe[0].readyState != "complete") {
setTimeout("RapportIframeComplete();", 100); }
else {
jQuery(RapportIframe[0]).attr('style','overflow:hidden;height:1750px;width:800px'); }
}
jQuery(document).ready(function() {
RapportIframe = jQuery('iframe[id^=ReportFrame]');
RapportIframeComplete();
});
</script>
I uploaded jQuery to the layuots-folder of Sharepoint. Set the Reportviewer webpart to async rendering. The height and width in the code are set to a value that is big enough, so that nothing of my reports is hidden.
Is this problem browser-specific?
I know with the the Report Viewer control, I had to write some JavaScript to resize the control. Perhaps a similar approach would work here. You can load any scripts or style sheet files to the _layouts folder in the SharePoint site.
I had the same issue time ago. Maybe is too late but here is the solution:
<script language="JavaScript" type="text/JavaScript">
window.onload =
function setstart() {
var els = document.getElementsByTagName('div');
var i = els.length;
while (i--)
if (els[i].id.indexOf('uc') > 0) {
els[i].style.overflowX = 'hidden';
els[i].style.overflowY = 'hidden';
}
}
</script>
you must locate this script on the page head. In this example, the script hidde the scrollbars to all user controls called 'uc[SOMETHING]'.

is it possible to clear struts2 file input tag?

I am using Struts2 for a web application development. i have this particular problem for which i couldnt find a solution even after i googled.
I have 3 tags with a hyperlink or button against each, which has to be used to clear the filepath if anything was previously selected. The solution which was found online was to reset the form.. but then all the s:file tags will be cleared since all tags need to be in the same form.
Is there any way to clear a single file input on some click??
One solution similar to what we've used is to remove the input element and create a new input element in its place, with the same name.
EDIT: Here's an example I threw together.
<script type="text/javascript">
function clearFoo() {
var inp = document.getElementById("foo");
var parent = inp.parentNode;
// Create the new input element.
// Copy over any attributes you need.
var newInp = document.createElement("input");
newInp.type = "file";
newInp.name = inp.name;
// Replace the old node with the new node.
parent.insertBefore(newInp, inp);
parent.removeChild(inp);
// The new node is the new "foo".
newInp.id = "foo";
}
</script>
<s:file id="foo" name="foo"/>
<button onclick="clearFoo();">Click</button>

Resources