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
  • 69,403
  • 10
  • 107
  • 109
Letholdrus
  • 1,261
  • 3
  • 20
  • 36

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
  • 41,620
  • 7
  • 58
  • 90
1

You can use this code:

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

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