That's true - I didn't change it because I thought there could be some cases
where alertSave() could be called outside of the 'a' thing - if that's not
the case, then this version is definitely better. You could go so far as to
eliminate the variable as well and just do:
if ($('#changedAppointments').attr("value").length > 0) { return
confirm(<MESSAGE>); }
Since you don't use dataControl more than the one time, there's really
little need for it.
James
Sam Collett wrote:
>
> On 05/03/07, James Thomas <[EMAIL PROTECTED]> wrote:
>>
>> 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;
>> }
>> }
>
> Or an even shorter way:
>
> $("a").click(alertSave);
>
> function alertSave() {
> var dataControl = $('#changedAppointments').attr("value");
> if (dataControl.length > 0) {
> return confirm("You have made changes to this date
> which have
> not been saved.\n\nAre you sure you want to navigate from this
> page?");
> }
> }
>
>
>>
>>
>> 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/
>>
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
>
--
View this message in context:
http://www.nabble.com/confirm-link-tf3350646.html#a9335673
Sent from the JQuery mailing list archive at Nabble.com.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/