• Feed RSS
Last week(22th january,2010), I become married from single. My wife's name is 'Mahfuja nilufar'(nickname: nila). This is the modest ceremony ever I have participated(may be i couldn't even this time if it wasn't my marriage :D).

I don't what is on my future life, but I always pray to almighty god to give me a happy and honest life to live along with my wife. Also wish to get all happiness of a married life and get rid of all pains of bachelor life...
Blogger blog has a common feature. Google set a navigation bar to the top of the page by default for navigate to next blog, goto account etc. This is public and whenever it is visited by someone he/she will see this navigation bar even if he/she not a google account holder or not signed in. This may disappointed some blogger. I myself, don't like it. So, Now we are going to remove that.

If you are familiar with web programming/development(specially html/css), you should solve this problem very easily.

* View source, check/inspect which element is that, set that elements visibility property to 'hidden' or display property to 'none'

If you are a pure blogger, don't know anything about html/css programming, then for you here is the simple solution:

* Go to You blog admin panel's 'layout' tab, then 'edit html' section. Find the <style> tag just after that, add the following code snippet:

#navbar-iframe {
height:0px;
visibility:hidden;
display:none;
}

Now save your template and you should get your job done. Enjoy!!!!!!!!!
I saw many people having a wrong idea about tdd. Many people thinks it to develop a code first and then write code that tests its validity. But, in real, they are wrong. Actually, Test Driven Development, or TDD, is a software development technique that is made up of short iterations where tests are written first and then code is written to satisfy the test condition. To use a more concrete example, if we wanted to write a method to validate an email address, we would write the test first that covers this use case and then write the method to make the test pass.
The very basic TDD life cycle consists of the following sequences:


1. Add a test: Create a test to satisfy a requirement. In our example, we would create a test that
calls the email validation method with an invalid email address.
2. Run the tests: Since we haven’t written any code, the test should fail. This is an important step because it validates that the test won’t always pass, which would make it worthless. Initially, you can’t even run the tests because you will have compiler errors, since you haven’t written the code your test is calling yet.
3. Write code: Write code to satisfy the test condition. In this case, you will create the IsValidEmail method to validate an email address.
4. Run the tests: The tests should now pass. If they fail, then repeat step 3 until they pass.
5. Refactor: Now that the requirement is met, we can refactor our code. Re-run the tests as you refactor the code to make sure that you have not broken anything. The preceding cycle is repeated throughout the development process for each new feature that needs to be added.
I am working with Jquery for few months. Since the very beginning , I was very pleased with their very very rich and strong live documentation. But, this isn't always enough. We always fell in critical problems and need others help. For this purpose, I found their google group. I joined. That helped me getting response of all my queries. But it created another problem, that is, my email Inbox started become flooded with Jquery group emails. I then created a filter with the Jquery email address and skipped my inbox. Although it helped a little, but still, I just didn't like getting that much emails on my mailbox anymore. I was just wondered why they aren't opening any official forum.

May be, now they/most other members are having problem also and they just launched their official forum. I am very much glad with this because, forums are a very helpful and user friendly platform for discussing problems doubts. If you are having same problem or even didn't know about the group either, just be relax as you can be a part of the Jquery developers community more easily from now on. Please visit Jquery Forum and get your account now, get discussing with other Jquery experts Instanly, get your problems solved!!!!!!
There are more than one ways to attach an event with an element. Like, you can attach a focus event with an input box as like follows:

  <input type="text" id="testName" onclick="EventHandlerFunction()" />


Also, it can be done in another way, inside script tag like as follows:


 <script type="text/javascript" >
window.onload=function(){
    document.getElementById('testName').onfocus = function(){
                    //do something      
    }
}
 <script>       


Remember, window.onload part is crucial. The attaching events are always need to be attached after the document object model(DOM) loaded properly. If you try to attach event outside this function, you will get an script error like stating that no such element found(this is natural as before the this element loaded, script won't found anything as this).

The above functionality can also be done in jquery easily as follows:

$(document).ready(function({
     $("testName").bind('focus',fucntion({
                                  //do something 
                           }));
}));


the $().bind() is the most  generic form for attaching event. However you can do shortcuts for several common event like


  $("testName").focus(fucntion({
                                  //do something 

                           });)


Now consider this situation, you are making some DOM element on the fly, dynamically with your JavaScript. You want to attach event with them. You can do this in either of the following way:

//basic javascript
var dynamic_element = "<input type="button" onclick="ClickhandlerFnction()"></input>";
obj.innerHTML = dynamic_element;

//jquery
var dynamic_element = $("<input>");
dynamic_element.attr("type","button");
dynamic_element.click(ClickhandlerFnction);


now, think, if you have to make several elements(but of same type, like same tag name or same class), you will have to go thorough a loop or have to attach event to all of them manually.

Another situation, you are getting html response through ajax request and you are interested to attach event to some of those elements, either you have to do it after receiving the ajax response or have to run a continuous function with setting interval to check whether any object of the specific type has been on the document.

You can have a better solution with jquery. From jquery 1.3.x , there is a new method implemented name live that do our this kind of complex jobs simply. you can attach event to an element that not yet on the DOM, but will be available anytime in future, jquery will keep track of that and will attach that event handler as soon as it find an element of that particular type. simply write:

$(element).live('click',EventHandlerFucntion);

and you are don't be worry about whether this element is currently exist or not, or when some request is going to bring it, you just got it. You can read more about live function on jquery's live documentation.
In two most popular programming scripting language, php and JavaScript, do support an interesting function, eval(). Its functionality is quite simple, converts a string representation of some scripting statements into real scripting statements. Another scripting language, Action Script, also did support this method until Action Script 3.0 version. Its been avoided in Action Script 3.0, latest version.

So, this function will be very very useful for you while you are working with php or JavaScript. Lets try a simple example. Suppose you are getting a string like as follows:

$str = 'echo "hellow world"';

you need to print only the hello world part, not along with echo(echo is a php output helper for printing/writing response on documents, web services etc). Here if you use the following way:

eval($str);

this will perfectly o your job. This will convert your string into function PHP scripting language statement and thus executes it.

Another example. You are doing Ajax operation on your application and getting JSON data from server as response. Most of the times, you will get the response as string Like

var response = "{'data':{'name':'evalFunctionTester'}}"

if you try it to be use like JSON notation, you will get nothing. Now try the following:

eval("var jsonObject="+response);
alert(jsonObject.data);

now you can use temp as an functional JSON object.

But, you need to be careful while using this function, specially when you are using this function on third party data(just like the JavaScript example), because they can return harmful/security-breaker code, you need to be sure that that code is safe to be parsed. In this case, the following function will help you:

decode: function(string, secure){
if ($type(string) != 'string' || !string.length) return null;
if (secure && !(/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(string.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, ''))) return null;
return eval('(' + string + ')');
}

in the first parameter, send your data, and the second parameter, send a Boolean value whether you want it to be secure or not. You will get it correctly.
The two most popular data type are supported by asp.net web service are XML data and JSON data. To access a asp.net web service and get response in a particular format, we have give some special instructions through Jquery.

* Url is to be correct format.
* Data has to be posted using POST method.
* Parameter names and also types must be similar as of web service arguments.
* have to define data type.
* Have to define content type.
* Has to check the response type correctly.

to make up the url, you have use first the service file location and then the function name like as follows:

http://mydomain.com/servicefile.asmx/service_method_name


to post data to server asynchronously, Jquery has multiple methods. Such as, you can either use $.post() method or $.ajax({type:"POST"}) method.

suppose we are sending a number and a string, then data must be like as follows:


data: "{textData:'test text',numberData:100}"


notice the double quote around the data, its required, unless it won't work.

Suppose we are interested to get JSON data and also sending data in JSON format as well(most standard format to manipulate in javascript), they will be like as follows:

dataType:"json"
contentType:"application/json"


if you are interested to get XML data, use "text/xml" instead.

You will be able to receive data using response.d property. So, in summary, the code snippet can be as follows:


$.ajax({
type: "POST",
contentType: "application/json",
dataType: "json",
url: options.url,
data:"{textData:'test text',numberData:100}",
success: function(data){
mydata = data.d;
//do whatever you need to....
},
error: function(result) {
alert("Failed " + result.status + ' ' + result.statusText);
}
});


Your Jquery code should now be able to talk with asp.net web service.