Wednesday, December 24, 2008

Insert HTML Tag Using Javascript...

The below mention function will be use to insert a div tag along with input field, button when a user clicks on hyper link. Button will be used to hide the selected div. A user can create max 5 div.


function attachFile(id)
{
var count = new Array("1","2","3","4","5")
var hiddenCount = document.getElementById("Cnt").value;
var Comman = 1;


for(var j=1;j<=count.length;j++)
{
if (id == 'remove_' + j)
{
document.getElementById('div_' + j).style.display = "none";
return
}
}
Comman = parseInt(hiddenCount) + Comman;
if (Comman <= 5)
{
var varTag1 = document.createElement("INPUT");
// var varTagRemove = newElement("input",{type:"button",name:"Remove",id:"remove_"+Comman,value:"1"},{onclick:attachFile(this.id)});
var varTagRemove = document.createElement("INPUT");
varTagRemove.type="button";
varTagRemove.value = "Remove";
varTagRemove.id = "remove_"+Comman;
varTag1.type = "file";
varTag1.id = "file_"+Comman;;
var x = document.all;
var br = "br"
if(x)
br = "
"
var varTag2 = document.createElement(br);

document.getElementById("div_" + Comman).appendChild(varTag1);
document.getElementById("div_" + Comman).appendChild(varTagRemove);
document.getElementById("div_" + Comman).appendChild(varTag2);
var rm_test = document.getElementById("remove_" + Comman);
rm_test.onclick = function(){attachFile(this.id)};
document.getElementById('Cnt').value = Comman;

}
else
{
for (var i = 1; i <= count.length; i++)
{
if (document.getElementById("div_" + i).style.display == "none")
{
document.getElementById("div_" + i).style.display = "block";
return
}
}
//ALERT WILL BE CALLED WHEN THE COUNT OF FILE UPLOADER IS 5 AND ALL THE DIV DISPLAY PROPERTY IS
// BLOCK
alert("Limit is over");
}
}

Thursday, December 11, 2008

Ruby: How "send" method works?

Invokes the method identified by symbol, passing it any arguments specified. You can use __send__ if the name send clashes with an existing method in obj.
For example.
Suppose that in you have a three different parameter
1.addnum
2.subnum
3.multinum

depends on the parameter you want to call the method to execute add/subtract/multiply. So what you can do

class Number

def mainfunction(methodname, val1, val2)
#THE BELOW MENTION SEND METHOD WILL CALL ANY ONE METHOD #DEPENDS ON THE FIRST PARAMETER
self.send(methodname, val1, val2)
end

def addnum(val1, val2)
val1 + val2
end

def subnum(val1, val2)
val1 + val2
end

def multinum(val1, val2)
val1 + val2
end
end

num = Number.new
num.mainfunction(“addnum”, 10 , 20) #output => 30

So this is just a very basic example to understand hoe send method work.