I'm not sure if I'm misinterpreting how to use the "one()" event
handler properly, but when I tried to use it in the bit of code below,
I was unable to prevent the button from submitting the form (which it
was now inserted into). I tried "return false" as well as an
"event.preventDefault()", but clicking on the button still seemed to
submit the form.

The only way I could get it to prevent submitting the form was to use
the .mouseup() event handler rather than .one().

Why didn't "return false" or "event.preventDefault();" stop the form
from being submitted?

The code:

$('#modewc').parent().append('<br /><br /><button style="font-size:
10px;" id="remHwb">Remove Word Breaks</button>');

if(!$("[EMAIL PROTECTED]'preview']")[0]){

        $('#remHwb').attr('disabled','disabled');

}
else{
        $('#remHwb').one("mouseup", function(e){

               e.preventDefault();

                var sdf = $.trim($('.bodytext:last>p').html()).split("\xAD\x20")

                $('#body').val('');

                for(var p=0;p<sdf.length;p++){

                        if( (p == sdf.length-1) && ((sdf[p].length<34) || 
(sdf[p].indexOf('
')> 0)) ){

                                
$('#body').val($('#body').val()+sdf[p].replace(RegExp("<br>",
"gim"), "\n"));

                                break;

                        }
                        else{

                                sdf[p] = 
sdf[p].slice(0,-2)+'[**]'+sdf[p].slice(-1);

                        }
                        sdf[p] = sdf[p].replace(RegExp("<br>", "gim"), "\n");

                        $('#body').val($('#body').val()+sdf[p]);

                }

                $(this).attr('disabled','disabled');

                return false;

        });
}

Reply via email to