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 over 13 years of experience in the full software development life cycle for Windows, services, and web-based applications using Microsoft .NET technologies. Demonstrated expertise in delivering all phases of project development—from initiation to closure—while aligning with business objectives to drive process improvements, competitive advantage, and measurable bottom-line gains. Proven ability to work independently and manage multiple projects successfully. Committed to the efficient and effective development of projects in fast-paced, deadline-driven environments. Skills: Proficient in designing and developing applications using various Microsoft technologies. Total IT Experience: 13+ years

Previous Post Next Post

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