0

I am trying to clear all the text boxes on a form if the user clicks on any one of them. Basically I have some fields from a db from which to search as rows in a table. Then there is a radio button for each row. I want to have it setup so that when the user clicks in a text box it all the other text boxes on the form must have their values set to ''.

So far this code works to clear the current text box:

    $(document).ready(function() {
        $('.novalue').focus(function() {
            $(this).val("");
        });
    });

All my text boxes in the table has the class="novalue" property. I just cannot figure out how to make it clear all and not just the one.

Sven
  • 66,463
  • 10
  • 102
  • 105
Letholdrus
  • 1,221
  • 3
  • 19
  • 35

2 Answers2

2

You were very close. But you don't want to reset $(this), but all input fields of that class:

$(document).ready(function() {
    $('.novalue').focus(function() {
        $('.novalue').val("");
    });
});
arkascha
  • 39,439
  • 7
  • 52
  • 86
1

You can use this code:

http://jsfiddle.net/V7j3b/1/

$(document).ready(function () {
    $('.novalue').focus(function () {
        $('.novalue').val("");
    });
});
amatellanes
  • 3,517
  • 2
  • 14
  • 19