Forum Moderators: open
<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?
Cheers!
Then in your JS you can access / post the variable like so:
$(".dateLink").click(function(){
$.post("myscript.php", {
dateVar: $(this).attr('dateVar')
},
function(xml){
//do something here onn call back
});
});
hope this helps
Ally
jQuery(document).ready(function(){
$('.calendarLink').click(function(ev)
{
var prefix = 'date_';
var date = this.id.substring( ( prefix.length ) );
$.ajax({
type: "POST",
url: "script.php",
data: "date="+date,
success: function(msg){
$('#result').html(msg);
}
});
});
});
<a href="javascript:void(0);" class="calendarLink" id="date_20081010">October 10,2008</a>
<div id="result"></div>
Thanks!