Get Paramater with Javascript

Normaly we get parameter in php is with $_GET[“”], but get paramter with javascript its a different case. Hopefully this will help :


<script>
 var search = window.location.search.substring(1);
 var complete_param = search.split(“&”);
 for(var i=0;i<complete_param.length;i++)
 {
 var single_param = complete_param[i].split(“=”);
 if (single_param[0] == variable) {
 return single_param[1];
 }
 }
</script>

**variable = is the parameter that you would like to get

First the code gonna detect all the parameter with “window.location.search” and after that it gonna splits with “&” and loop it. In the loop, it gonna split again with “=” so you will get value of your parameter one by one.

Leave a Reply

Your email address will not be published. Required fields are marked *