views:

244

answers:

0

Hi in the code below :

1) The form submit action is changed by the document ready fn to make an ajax call

2) If the data from the ajax is not 'No probs' then it puts the error message in a div and changes the value of the submit, so that a second click takes you to the standard action. This bit works.

3) If there is not an error I want it to post the standard action: See alert('Fred1'); (here I have tried $('#addcreditdetails').submit() also

I have tried lots of things but cannot get 3) to work.

    <script>

    var chrisReady = function () {

     var submitFunction = function (event) {
      //console.log(submitval);

      var chrisPoster = function (data) {
       alert(data);
       if (data=='No probs') {
        $('#dealwarning').html('CC');
        alert('Fred1');
        $('#addcreditdetails').unbind('submit');
        $('#addcreditdetails').submit();
        alert('Fred2');
       }
       else {
        $('#dealwarning').html(data);
        $('#submit').val('Confirm Add Credit');
        jQuery('#addcreditdetails').unbind('submit');
       }
      };

      var amountval = $('#amount').val();
      var currval = $('#curr').val();
      var accountnoval = $('#accountno').val();
      var submitval = $('#submit').val();


      var postData = { 
       amount: amountval,
       curr: currval,
       accountno: accountnoval,
       submit: submitval
      };

      $.post('docheckcredit.php', postData, chrisPoster);
     }

     $('#addcreditdetails').bind('submit', function (event) {
      event.preventDefault();
      submitFunction(event);
     });
    }

$(document).ready(chrisReady);
</script>";