views:

162

answers:

0

(This post is vaguely related to a previous question, but since then I've rewritten a lot of code and it makes sense to start again.)

I am using the jquery form plugin to submit a form to a cakephp action. I use the 'toggleVal' plugin too, to give my input fields placeholder text.

All I am trying to do is to use the beforesubmit callback to check the input field values and if they match then clear them out, so my cake action can deal with the empty fields.

Although I clear each input on a match using the following function, it doesn't appear to affect the post itself, as the values remain.

function checkValues(){

    $(".toggleval").each(function(){

     alert('match');

     if($(this).val() == $(this).data("defText") ){
      $(this).val("");
     } 
    }); 
}

If I put the checkValues function on a submit() event, and omit the ajax, it DOES INDEED work and clears the values in the post. However, as soon as I introduce the ajax part, it doesn't clear the post values. I've tried running it before a standard jQuery $post() and as part of the beforesubmit: callback in the jquery form helper. Both times it seems the ajax post does not want to be cleared.

I'm stumped now. Can anyone see why this is happening? Many thanks.