Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Friday, February 19, 2010

getElementById is not working in fire fox

For hidden fields the following code will not work in firefox
document.getElementById("AttachName").value = fname;
it should be
document._frmUpload.AttachName.value = fname;
Here _frmUpload is the form name.
AttachName is field ID.
So better use the second one if you know the form name.

Saturday, February 6, 2010

IE is losing ClearType if you use jQuery hide or fadeIn

IE is losing ClearType if you use jQuery hide/show or fadeIn/fadeOut or even when you open a remote page.

$('#myDiv').hide();

$("#myDiv").fadeIn('slow');


The problem seems to be that the CSS "filter" attribute is not automatically removed. The most simple solution to this problem would be removing it manually :)


$('#myDiv').fadeIn('slow', function() {
this.style.removeAttribute('filter');
});

But the above solution looks odd because for each hide you need to remove manually.

A simple, more elegant solution would be to wrap the .fadeIn() and .fadeOut() functions with a custom function via the plugin interface of jQuery. The code would be exactly the same, but instead of directly calling the fade functions, we call the wrapper.

$('#node').customFadeOut('slow', function() {
//no more fiddling with attributes here
});

So, how do you get this working? Just include the following code after you include the jQuery library for the added functionality.

(function($) {
$.fn.customFadeIn = function(speed, callback) {
$(this).fadeIn(speed, function() {
if(jQuery.browser.msie)
$(this).get(0).style.removeAttribute('filter');
if(callback != undefined)
callback();
});
};
$.fn.customFadeOut = function(speed, callback) {
$(this).fadeOut(speed, function() {
if(jQuery.browser.msie)
$(this).get(0).style.removeAttribute('filter');
if(callback != undefined)
callback();
});
};
})(jQuery);

Bug in Lotus 8.5.1 ? jQuery script is giving error while saving in Lotus 8.5.1 script library as javascript code

jQuery script is giving error while saving in Lotus 8.5.1 script library as javascript code.

Error screen shot:


Is that problem with jQuery (i dont think). This could be a problem with Lotus 8.5.1 javascript script library.

What do you think?

Sunday, September 20, 2009

Showing alternate coloured rows on Web

There has been quite a few solutions to produce alternate row colors for a Web view. They all involve writing cluttered HTML in the column headings, treating view contents as HTML, or using agents, etc. But the following solution is purely a javascript function and has nothing to do with Domino view design. Part of this idea was derived from a posting in the notes.net site.



Step 1.) Create a view with few columns(Let it be uncategorized initially).

Step 2.) Embed the view in a form(Display as HTML).

Step 3.) Put the following code in the Onload event of the form.(Or have it as a function in the JS Header and call it in the OnLoad event).


var tableElements = document.body.all.tags("table");
var table = tableElements[tableElements.length-1];
var headlength=rowlength="";
heads = table.getElementsByTagName("th") ;
headlength=heads.length;

// If the view is categorized , use this line, else comment it
//headlength=headlength-1;

for( i = 0; i <headlength; i++)
heads[i].bgColor = '#D2D2D2';

rows = table.getElementsByTagName("tr") ;
for( i = 0; i < rows.length; i++)
{
if(i % 2)
{
// If the view is not categorized , use this line
celllength=rows[i].cells.length;
// If the view is categorized , use this line
//celllength=rows[i].cells.length-1;

for (var c = 0; c < celllength; c++)
rows[i].cells[c].bgColor = '#F4F4F4';
}
else
rows[i].bgColor='';
}

(The code is self explanatory. It gets the table element, changes the background color of the cells. The above code works fine for an uncategorized view.)

Step 4: For a categorized (single or many), uncomment the following lines,

//headlength=headlength-1;
//celllength=rows[i].cells.length-1;

and comment the following line.
//celllength=rows[i].cells.length;

This should work well for a categorized view.

Step 5 : To provide alternate column color effect, modify the for loop given below,

for (var c = 0; c < celllength; c++)
rows[i].cells[c].bgColor = '#F4F4F4';

to,

for (var c = 0; c < celllength; c++)
if (c % 2)
rows[i].cells[c].bgColor = '#F4F4F4';



The above javascript function is fully customizable like,
table.cellspacing='2'
table.cellpadding='2'
and the bgcolor values etc.

Return to previous page after submit in javascript

Place in a $$Return field on a form.



More clear picture


Thursday, September 10, 2009

Set the value of combobox in javascript, set the value of html select value in javascript

Problem: Set the value of a combobox in javascript
Solution: For combobox give the values and names.
for ex:


Screenshot:
Javascript code to set the value of combobox:
document.forms[0].Combo.value="Test2";
i put the above code in Onload of the body. so by default the combo box value is "Test2".
The above code should work 99%. If the above javascript code is not working then use this:
for (var i=0; i (lessthan symbol here) document.forms[0].Combo.length; i++) {
if (document.forms[0].Combo[i].value == "Test2") {
document.forms[0].Combo[i].selected = true;
}
}




Wednesday, September 9, 2009

Refer a field value in iframe from parent window

Hi today i came across to read a field value of iframe from a main parent window.

Here is the javascript code:

var temp = document.getElementById('iframeid').document.getElementById('fieldID').value;

Its so simple... Right?

Search This Blog