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>
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.
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).
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.
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.
use this code:
var a = location.href;
var b = a.substring(a.indexOf("?")+1);
use javsacript and type:
location.search
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With