0

I having url in query string like http://www.domain.com:3000/allot_room?floor=6&hostel=1&student=1.In that, how to get student parameter value using jquery.

I have used this code

var url = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

It shows like floor=6,hostel=1,student=1.In that how to get student parameter value.And I tried different codes.

2 Answers 2

2

use var url = window.location.search

and from MDN -

Get the value of a single window.location.search key:

function loadPageVar (sVar) {
  return decodeURI(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + encodeURI(sVar).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
}

alert(loadPageVar("floor"));
alert(loadPageVar("student"));

More about window.location

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

Comments

2

try

window.location.search

see mozilla documentation

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.