Get URL GET values using javascript

I had a situation of getting URL GET values to my web page without using server side scripting language like PHP, JSP or ASP.

So this is a simple way to get URL GET value to your web page using javaScript. When you don’t have any facilities to code server side scripts, you can use this technique to make your website more dynamic.

Simple example :

     <script>// Import GET Vars
           document.$_GET = [];
           var getVarsString = String(document.location).split('?');
              var getVars = getVarsString[1].split('&');
              for(var i=0; i<=(getVars.length); i++){
                    var getVarPair = getVars[i].split('=');
                    document.$_GET[getVarPair[0]] = getVarPair[1];
         function updateView(){
      <input id="txt" type="button" value="click" onclick="updateView();" />
      <div id="view"></div>

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>
var $j =jQuery.noConflict();

⁄ ⁄ Use jQuery via $j(…)
var textbox1 = $j(‘#textbox1’).val();


⁄ ⁄ Use Prototype with $(…)


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.

<meta equiv=”refresh” content=”0;URL=enable_js.html”>

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.
alert(“Javascript enabled successfully! Press ok to continue”);
window.location = “index.html”;

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.

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’);
return false;
use this javascript function to validate email addresses.
%d bloggers like this: