Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

jquery - accesing link variables

8:13 pm on Oct 30, 2008 (gmt 0)

New User

10+ Year Member

joined:Dec 17, 2004
votes: 0

I'm a beginner when it comes to jquery, spend most of my time with php/mysql and simple javascript. I've been searching high and low for a demo on how to access a variable in a url when calling jquery's post method. Basically I have a whole pile of links that have dates attached to them, ie.:

<a href"domain.com?var=20081031">

Using jquery's post method I need to send that date to an external file and then do some fun stuff with it server side. I know how to structure the function with the post method by I don't know how to pass the date as a parameter, ie. how to access it.

All the tutorials I've seen use forms so they have onclick events which just grab the id of the element, which doesn't help me for a few reasons. (Elegant deprecation for onclick, and multiple variables.) I would even be fine with passing the entire url and parsing it server side. I just need to post that date!

Does anyone familiar with jquery have an idea?


11:08 am on Oct 31, 2008 (gmt 0)

Full Member

10+ Year Member

joined:Aug 3, 2005
posts: 269
votes: 0

could you change the link slightly so that you put the date variable that you need into an attribute?
<a href="#" class="dateLink" dateVar="20081031">Click me baby!</a>

Then in your JS you can access / post the variable like so:

$.post("myscript.php", {
dateVar: $(this).attr('dateVar')
//do something here onn call back

hope this helps


4:48 pm on Oct 31, 2008 (gmt 0)

New User

10+ Year Member

joined:Dec 17, 2004
votes: 0

Good deal. The following works perfect:

var prefix = 'date_';
var date = this.id.substring( ( prefix.length ) );

type: "POST",
url: "script.php",
data: "date="+date,
success: function(msg){

<a href="javascript:void(0);" class="calendarLink" id="date_20081010">October 10,2008</a>
<div id="result"></div>