homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

jquery - accesing link variables

10+ Year Member

Msg#: 3777050 posted 8:13 pm on Oct 30, 2008 (gmt 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?




5+ Year Member

Msg#: 3777050 posted 11:08 am on Oct 31, 2008 (gmt 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



10+ Year Member

Msg#: 3777050 posted 4:48 pm on Oct 31, 2008 (gmt 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>


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved