0

I'm validating some input (type="text") boxes with JavaScript (jQuery).

They are on a $('').dialog() box wich appears when you click on a button.

When I show the dialog the first time everything works great with my verification Code:

function verifyContactForm() {
    formValid = true;
    txtSubject = $('#txtSubject');
    txtRoom = $('#txtRoom');
    txtMessage = $('#txtMessage');

    if (txtSubject.val() == "") {
       formValid = false;
       txtSubject.css('border-color', 'red');
    }
    else
       txtSubject.css('border-color', 'lightgray');

    if (txtRoom.val() == "") {
       formValid = false;
       txtRoom.css('border-color', 'red');
    }
    else
       txtRoom.css('border-color', 'lightgray');

    if (txtMessage.val() == "") {
       formValid = false;
       txtMessage.css('border-color', 'red');
    }
    else
       txtMessage.css('border-color', 'lightgray');

    return formValid;
}

After the user ended the dialog and everything is valid it sends the data to the server using a ajax call.

Now when the user opens the dialog a second time, without reloading the page, in my text elements the old text is still present. The text isn't shown in the input boxes, but when I select the text with .val() it still has the old text in it.

Does anybody know why this is like that?

I think it has something to do with caching, but I'm not sure so I'm asking this question.

Ben Everard
  • 13,652
  • 14
  • 67
  • 96
ok3n0b1
  • 83
  • 2
  • 13

2 Answers2

0

Call form_element.reset() after opening dialog or sending data.

Mics
  • 1,420
  • 14
  • 19
  • Sorry but that isn't working. I think the dialog isn't closed right. I saw that in code the old dialog is still present (display:none) but still present. – ok3n0b1 Jul 26 '12 at 08:41
0

The Problem could be solved with this solution.

The main problem is when you do not proper close the dialog and REMOVE it from the DOM you gonna have some problems...

jquery: How to completely remove a dialog on close

This link shows what I mean.

Community
  • 1
  • 1
ok3n0b1
  • 83
  • 2
  • 13