0

Hello guys i would like to know how to retrieve the value of 47 in this url by jquery so that i can use this value to display the specific records associated with the id

...../Rate.aspx#/HotelMobileBooking/Room.aspx?RT=47
ThiefMaster
  • 310,957
  • 84
  • 592
  • 636

3 Answers3

1

Simply use a regular expression for it. /Room\.aspx\?RT=(\d+)/ does the job:

> /Room\.aspx\?RT=(\d+)/.exec('/Rate.aspx#/HotelMobileBooking/Room.aspx?RT=47')[1]
'47'

If you want to access the value in the current URL, use location.hash to access the #... part of the url.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
  • Copied from the nodejs shell. Pretty much standard syntax to show that something was executed in an interactive interpreter (even though python's `>>> ` is more obvious). – ThiefMaster May 10 '12 at 08:32
  • Pardon me for asking i want to know the steps to do when the page first loads for Room.aspx because i am just a beginner at jquery – user1381205 May 10 '12 at 08:38
  • @user1381205. It has nothing to do with `jQuery`. – gdoron May 10 '12 at 08:47
1

no need to use a regular expression. If RT is the only parameter in your querystring just use split()

url = ".../Rate.aspx#/HotelMobileBooking/Room.aspx?RT=47";
url.split("?RT=")[1]; //47
Fabrizio Calderan
  • 120,726
  • 26
  • 164
  • 177
0

This question tells you how to retrieve a query string value using jQuery: How can I get query string values in JavaScript?

Assuming that the URL you posted is the URL of the page that you are on...

Community
  • 1
  • 1
Fiona - myaccessible.website
  • 14,481
  • 16
  • 82
  • 117