views:

44

answers:

1

Hello:

I am using Grails and the first part I have is a search field.

I am using this to create the CLEAR button, but it is not working:

$("#clear").click(function() {
    $(':input','#container')
        .not(':button, :submit, :reset, :hidden')
        .val('')
        .removeAttr('checked')
        .removeAttr('selected');
    $("#container #ScommodityList").empty();
    $("#container #SagentList").empty();
});

Does anybody know what I could be doing wrong?? Maybe the :input part?? In Grails they are called g:textfield

Something like this, but using Grails would be perfect!

http://jsfiddle.net/EPcnR/3/

Any help would be greatly appreciated

A: 

To clear a form, you might want to use javascripts native .reset().

$('#formid')[0].reset();
jAndy
What is the [0] ?? Is throwing me an error and I don't understand it.
fgualda87
Example: http://www.jsfiddle.net/Upv9f/
jAndy
@fgualda87: the [0] is getting the DOM element from the jQuery object, since `.reset()` is a native javascript / DOM method.
jAndy
@fgualda87 - Just keep in mind that `.reset()` will only clear the form if the initial values were clear. It resets to whatever the initial value was when the page was loaded.
patrick dw
For some reason is not working... Grails uses g:form, maybe that has something to do with it?? I've tried a lot of things and they don't work :/
fgualda87
This will only make everything to how it was when it started, I need it to set all the values to '' or selectedindex -1
fgualda87