Close ... try this:
$("a").click(function(){return alertSave($(this).attr("href"));});
function alertSave(url) {
var dataControl = $('#changedAppointments').attr("value");
if (dataControl.length > 0) {
if (confirm("You have made changes to this date which have not
been
saved.\n\nAre you sure you want to navigate from this page?")) {
document.location = url;
return true;
} else return false;
}
}
smeranda wrote:
>
> Still no luck, this is what I have:
>
> $("a").click(function(){alertSave($(this).attr("href"));});
>
> function alertSave(url) {
> var dataControl = $('#changedAppointments').attr("value");
> if (dataControl.length > 0) {
> if (confirm("You have made changes to this date which have not
> been
> saved.\n\nAre you sure you want to navigate from this page?")) {
> document.location = url;
> } else return false;
> }
> }
>
>
>
> James Thomas wrote:
>>
>> You need to return false if you don't want something to happen. so if
>> (confirm('whatever')) { do_whatever(); } else return false;
>>
>> smeranda wrote:
>>>
>>> When a user clicks a link and a form field currently has data, a
>>> confirmation box appears. This is close to working, but if a user clicks
>>> 'cancel' the browser still redirects to the a href URL. What am I doing
>>> wrong?
>>>
>>> $("a").click(function(){alertSave($(this).attr("href"));});
>>>
>>> function alertSave(url) {
>>> var dataControl = $('#changedAppointments').attr("value");
>>> if (dataControl.length > 0) {
>>> if (confirm("You have made changes to this date which have not
>>> been
>>> saved.\n\nAre you sure you want to navigate from this page?")) {
>>> document.location = url;
>>> }
>>> }
>>> }
>>>
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/confirm-link-tf3350646.html#a9320032
Sent from the JQuery mailing list archive at Nabble.com.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/