Getting querystring value using Javascript

Introduction

This article contains code snippet for getting querystring value using javascript

Code Snippet

This javascript function retrieves query string value from url taking querystring name as parameter

 <script>  
 function getParameterByName(name) {  
 url = window.location.href;  
 name = name.replace(/[\[\]]/g, "\\$&");  
 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),  
 results = regex.exec(url);  
 if (!results) return null;  
 if (!results[2]) return '';  
 return decodeURIComponent(results[2].replace(/\+/g, " "));  
 }  
 </script>  

Calling above function

This below javascript code calls above declared function for displya querystring value

 <script>  
 var vl=getParameterByName('id');  
 if(vl){  
 alert(vl)       
 }  
 </script>  

Summary

Hope this code snippet may help you to resolve your problem.

Thanks

Kailash Chandra Behera

An IT Professional with 12 years experience in development life cycle in windows, service and Web based application using Microsoft.Net technologies. Proven record of developing all phases of projects in Microsoft.Net technology from initiation to closure aligning with the company's Business objectives to drive process improvements, competitive advantage and bottom-line gains. -> Good exposure of independently working and developing multiple projects ->Committed to efficient and effective development of projects in a fast-paced and deadline driver environment. Skill :- Develop and design projects in various technologies of Microsoft Technology. Total IT Experience- 13+

Previous Post Next Post

نموذج الاتصال