Textbox watermark using simple javascript without Ajax or JQuery

Introduction

Using this example we can create the text box with water mark text without using any jQuery or jQuery Plug in.

Description:

In the previous examples, we have learned how to keep watermark text for the text box using AJAX control tool kit.

In this example we are using inline little bit javascript if condition by using onclick, onfocus and onblur events.

Code:

<html>
<head>
<title>www.jqueryexamplecode.blogspot.com</title>
</head>

<body>
<label>Watermark textbox</label>
<input type="text" value="jqueryexamplecode..." onclick="if(this.value=='jqueryexamplecode...'){this.value=''}" 
onfocus="if(this.value=='jqueryexamplecode...'){this.value=''}"
onblur="if(this.value==''){this.value='jqueryexamplecode...'}">
</body>
</html>

Output Video:


Output:



If you have any queries or suggestions, please feel free to ask in comments section.

Redirect one webpage to other using Javascript/JQuery

There are so many ways to redirect one javascript file to other. As per my knowledge i am showing below ways, If any one knows any other way they can tell in the comments section.



// it won't store information about previous page.
window.location.replace("http://aspnettutorialonline.blogspot.com/");

// best way to use
window.location.href = "http://aspnettutorialonline.blogspot.com/";

//using javascript only.
window.location = "http://aspnettutorialonline.blogspot.com/";


//Using JQuery way - 1
var url = "http://aspnettutorialonline.blogspot.com/";   
$(location).attr('href',url);


//Using JQuery way  - 2.
$jq(window).attr("location","http://aspnettutorialonline.blogspot.com/");

//redirecting to the home page.
window.location = window.location.host

How to implement validations on form controls using javascript before a postback occurs.


If we are using submit button in the form, we have to validation data before sending to the server. For this on submit we will call the javascript method. from the method we will return true or false based on the validation result.


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script type="text/javascript">
        function Validate() {
            //Need to do validations here. 
            //If any thing fails we have to return false other wise request go to server
        }
    </script>
</head>
<body>
    <form onsubmit="return Validate()">
        ... all controls will go here with submit button...
    </form>
</body>
</html>


If you have any queries or suggestions, please feel free to ask in comments section.