Search code examples
prototypejs

Prototype Class Clear Input


I"m a jquery guy, and Prototype is kicking me in the head right now.

I've got an input field, here:

<input type="text" value="" name="options[3]" class="input-text required-entry  product-custom-option" id="options_3_text" onchange="opConfig.reloadPrice()">`

and this prototype script:

function clearInput(){
    Form.Element.clear('options_3_text')
    Field.clear('options_3_text')
    $('options_3_text').clear()
}

and a button that is set onclick="clearInput();".

I'd like to get the INPUT by the class .input-text rather than the ID options_3_text. Any help getting that Class rather than ID or a better method would be fantastic!


Solution

  • Use the double dollar sign to get elements by css. Something like this should work(not tested!):

    $$('.input-text').each(function(e){ $(e).clear(); }.bind(this));
    

    http://www.prototypejs.org/api/utility/dollar-dollar

    Also, implementation of each can be found here if you need it: http://www.prototypejs.org/api/enumerable/each