Change the value of an input with jQuery or Javascript


I want to change the value written in 55 inputs that have the same class called input_valores_provisionales and different id (1,2,3,4 ...) in a function as soon as the page is loaded

here the script

 alert("alert para comprobar que la función se ejecuta"); // aqui OK

  $('.input_valores_provisionales').val("0"); // no funciona


I tried the following ways and it does not work either

$('.input_valores_provisionales > input').val("0");

notwithstanding this form if it works, and once I check that the class is well written, otherwise this would not be effective


but it does not help me because the zero does not take it as a numerical value, it is rather a 'phantom zero' that is displayed there and disappears when putting the cursor over the input, according to this the problem for me is not in that the jquery does not do its respective function if it does not seem that the input was "blocked" to write in the jquery or javascript, with the keyboard I can write normally

I tried to put the attribute value="0" to each of the 55 inputs and it did not work either

I tried to remove it and add the attribute type="text" and neither

Any idea what it can be?

asked by Gabriel Uribe Gomez 06.04.2018 в 07:46

1 answer


Do you have syntax errors? apparently it is necessary to close the ready of the document

})  // <- falta el )

I also recommend replacing the current ready with

$(function() {


$(function() {
<script src=""></script>
<input class="input_valores_provisionales" id="1" value="21432"/>
<input class="input_valores_provisionales" id="2" value="24" />
<input class="input_valores_provisionales" id="3" value="q434"/>
<input class="input_valores_provisionales" id="4"  value="2143w2"/>
answered by 06.04.2018 в 07:50