Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get url value after question mark in javascript

Tags:

javascript

How can I get the url value after a question mark in javascript?

I want the following behaviour:

if value is yes then 10+2 
else if value is no then 10.

I want to output with alert messages.

<div class="col-xs-4 col-sm-4 col-md-4 text-center width100">
    <a href="piccal.html" class="btn btn-success" id="yes">PIC Grant Calculator</a>
</div>
<div class="col-xs-4 col-sm-4 col-md-4 text-center width100">
    <a href="piccal.html" class="btn btn-danger" id="no">PIC Grant Calculator</a>
</div>

<script> 
if (value == no) {
    alert('hello');
}
</script>

<script> 
if (value == yes) {
    alert('hi');
}
</script>
like image 706
Ashish Mishra Avatar asked Feb 28 '14 11:02

Ashish Mishra


People also ask

What is URL after question mark called?

Parameters. Some URLs include a string of characters after the path—beginning with a question mark—called the parameter string. You have probably noticed this part of a URL appear in your address bar after performing a search on Google or YouTube.

How do you get a question mark out of a URL?

In a URL, the query starts with a question mark - the question mark is used as a separator, and is not part of the query string. If you also include a question mark in the query string, this would be treated as a literal question mark (i.e. it has no significance beyond that of a regular character).

Can you use Javascript to get URL parameter values?

The short answer is yes Javascript can parse URL parameter values. You can do this by leveraging URL Parameters to: Pass values from one page to another using the Javascript Get Method. Pass custom values to Google Analytics using the Google Tag Manager URL Variable which works the same as using a Javascript function.

Can a URL have a question mark?

What Does a Question Mark in URL Do? URLs have query strings that specify parameters through a group of characters typed into a browser to retrieve information. A question mark is not a part of the query string, but it's used to establish boundaries and is considered a separator.


2 Answers

use this code:

var a = location.href; 
var b = a.substring(a.indexOf("?")+1);
like image 121
kp singh Avatar answered Oct 20 '22 08:10

kp singh


use javsacript and type:

location.search
like image 40
AO_ Avatar answered Oct 20 '22 09:10

AO_