tags:

views:

21

answers:

2

Hi everybody,

I have a page with a form, I'd like with a button have reset button effect only on input text inside a div here is an extraxt of my code:

html:

<div id="new_prom" style="clear:both; padding:2px; border:1px solid red; margin:5px;">
<div>
  Codice <input type="text" id="cod_pro" name="cod_pro" class="short"> Sottocodice <input type="text" id="sotto_pro" name="sotto_pro" class="short"><br>
Nominativo<br>
<input type="text" id="nom_pro" name="nom_pro" class="long">
</div>
<div>
<div class="bt" id="bt_pro">INSERISCI</div> <div class="bt" id="resetta">RESET</div>
</div>

jquery:

$("#resetta").live('click', function()
{
   $("#new_prom > text").each(function(){$(this).val("")});
});

thanks in advance.

ciao, h.

+5  A: 

You almost have it correct, the selector is [type='text'] or :text, like this:

$("#resetta").live('click', function() {
  $("#new_prom :text").val("");
});

You can give it a try here, the other part is the .val(""), it'll work on all matched elements when setting, no need to loop in a .each().

Nick Craver
I have tryed your code but not work in my case :(
haltman
@haltman - Did you remove the `>` in the selector like I have above and in the example? None of your inputs are *direct* children of `#new_prom`.
Nick Craver
Thanks to Nick Craver and Spinon that's working code for me:$("#resetta").live('click', function() { $("#new_prom :text").each(function(){$(this).val("")}); });
haltman
@haltman - Again, you don't need that `.each()`, see my code above...
Nick Craver
+1  A: 

Think you forgot the colon.

$("#resetta").live('click', function() 
{ 
   $("#new_prom :text").each(function(){$(this).val("")}); 
});
spinon
I have tryed your code but not work in my case :( I've to say for understand better my problem that html and jquery codes are not in the same page
haltman
Yeah as @Nick mentioned I missed that the text elements are not direct children and didn't notice you had that. I was just fixing the text selector. So you need to remove the > sign like in my edit.
spinon