Latest Entries »

Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Sunday, November 7, 2010

solution for prototype.js and jquery.js conflict problems

Jquery have provide a solution for prototype.js and jquery.js conflicts. There is one caveat: By default, jQuery uses "$" as a shortcut for "jQuery". However, you can override that default by calling jQuery.noConflict() at any point after jQuery and the other library have both loaded. For example:


<script src="prototype.js"><⁄script>
<script src="jquery.js"><⁄script>
<script>
var $j =jQuery.noConflict();
$j(document).ready(function(){

⁄ ⁄ Use jQuery via $j(...)
$j('#button1').click(function(){
var textbox1 = $j('#textbox1').val();
alert(textbox1);

});

⁄ ⁄ Use Prototype with $(...)
$('someid').hide();

}
<⁄script>

Wednesday, May 5, 2010

How to detact javascript is enable or not in the client browser

There are various kind of solution to check the javascript support of client browser. In here I'll provide a solution to block client access who have not enabled javascript in his/her browser.

In this example I user index.html which clients want to visit. And user enable_js.html which will redirect clients from index.html page when their browser not support to javascript.


<noscript>
<meta equiv="refresh" content="0;URL=enable_js.html">
</noscript>


Add above code into the body (between body tags) of index.html. This part will redirect clients who user browsers which not support for javascript to enable_js.html. If javascript is enable, then nothing happent from this code.



<h2 id="nojs" style="font-family: Verdana,Arial,Helvetica,sans-serif; color: rgb(204, 0, 0);">
JavaScript is turned off in your web browser. Turn it ON (Enable) to access the website, then refresh the page.
</h2>
<script>
document.getElementById("nojs").style.display="none";
alert("Javascript enabled successfully! Press ok to continue");
window.location = "index.html";
</script>


Add above code into the body of enable_js.html. This will display error massage when javascript is disable in client's browser. After enable javascript and refresh this page will provide alert with informing the javascript is successfully working. And after press ok it will redirect to the index.html.

Tuesday, September 29, 2009

javascript mail validation (check)

var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(txtEmail.value)) {
alert('Please provide a valid email address');
txtEmail.focus();
return false;
}

use this javascript function to validate email addresses.