Hello , I have just started learning Jquery and am new to writing javascript (I am too old to write noob it feels wrong).
Scenario: I have a hyperlink that opens a dialogue box and sets a cookie. The dialogue box is asking something like "would you like to visit this page are you sure? " it has Yes/No buttons on it.
If the user clicks yes i would like the script to retrieve the link originally clicked and go to that page. I have done it by retrieving the value of the cookie. Although this works i am sure i could do it with a variable but i do not know how as the dialog box is in a separate function.
So my Question: Can i use the variable that sets the cookie and bind it to the yes button in the dialogue? What would the syntax look like?
thanks in advance
Hairby
Code is below
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("a").click(function () {
var cookieset = $(this).attr("href");
$.cookie("redirectcookie", cookieset, { path: '', expires: 7 });
$('#dialog').dialog('open');
$(".ui-dialog-titlebar-close").hide();
return false;
});
$('#dialog').dialog({
autoOpen: false,
width: 600,
buttons: {
"Yes": function() {
window.location = 'http://www.mysite.com'+ $.cookie("redirectcookie")
},
"Cancel": function() {
}
}
});
});
</script>