Reputation: 23
I have a login form (which opens in a jquery popup) that redirects after successful login back to the previous page.
I would like to populate a hidden redirect input within this login form with the value of the clicked link url, ie:
<script type="text/javascript">
$(function() {
$("a.login").click(function() {
if($(this).hasClass("selected")) {
deselect();
} else {
$(this).addClass("selected");
$(".pop").slideFadeToggle(function() {
$("#email").focus();
});
}
return false;
});
$(".close").live('click', function() {
deselect();
return false;
});
});
$.fn.slideFadeToggle = function(easing, callback) {
return this.animate({ opacity: 'toggle', height: 'toggle' }, "fast", easing, callback);
};
</script>
<form>
<input type="hidden" name="redirect_url" value="clicked_link_url" />
</form>
<a href="clicked_link_url_1" class="login">Link 1</a>
<a href="clicked_link_url_2" class="login">Llink 2</a>
<a href="clicked_link_url_3" class="login">link 3</a>
So if the user clicks link 3, the popup form opens and it's hidden redirect url value will be "clicked_link_url3".
Thanks in advance.
Upvotes: 2
Views: 524
Reputation: 73896
$("a.login").click(function () {
if ($(this).hasClass("selected")) {
deselect();
} else {
$(this).addClass("selected");
$(".pop").slideFadeToggle(function () {
$("#email").focus();
});
}
// Set the input value
$('input[name="redirect_url"]').val($(this).attr('href'));
return false;
});
Upvotes: 2