0

Issue: Read the parameter from url and display in HTML after necessary formatting

Description: URL: www.abc.com/test.html?name=Raj%20Sharma%20&%20Anjali%20Sharma

On Click event it should show the following:

Raj Sharma & Anjali Sharma

What I have till now is the following code:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function getParameter(){
var param1var = getQueryVariable("name");
document.getElementById('demo').innerHTML = param1var;
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
} 
alert('Query Variable ' + variable + ' not found');
}
} 
</script>
</head>
<body>
<h1>Testing</h1>
<a href="javascript:void(0)" onclick="getParameter()" id="continue">Click</a>

<p id="demo"></p>

</body>
</html> 

I am really new in writing JS.

0

1 Answer 1

2

This is enough to get that output:

 var query = decodeURIComponent(window.location.search.substring(1).split('=').pop());

query: "Raj Sharma & Anjali Sharma"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.