Set input type of text value by classes in one line

I make a class selection by class name in the radio buttons, and it works. Then I want to make a class selection by name in text attachments and set values ​​for any text. I couldn’t do this.

How can I make the same setting value for my text fields

Here is my code

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Encuesta</title> <link href="css/smoothness/jquery-ui-1.9.1.custom.css" rel="stylesheet"> <link rel="stylesheet" type="text/css" href="css/main.css" /> <link href="css/helper.css" media="screen" rel="stylesheet" type="text/css" /> <script src="js/jquery-1.8.2.js"></script> <script src="js/jquery-ui-1.9.1.custom.js"></script> <title>Ejemplo Radio Button</title> <script> $(document).ready(function(){ var predeterminar=2; //This line works fine $("[class=radiomarcado]").filter("[value='"+predeterminar+"']").prop("checked",true); //$("[class=nsnr]").prop("value","NS/NR"); //$("#p074, #p076, #p078").prop("value", "NS/NR"); // but this does not set the value by class // if you can see I try other ways to do $('.input[type="text"][class="nsnr"]').prop("value", "NS/NR"); //$('input:radio[class="nsnr"]').prop("value","NS/NR"); }); </script> </head> <body> <form name=fcolores> <table class="gridtable2"> <caption>3.5 ¿Cuál es la cantidad promedio de empleados en el año 2011 que al interior de su empresa se dedicaron a las siguientes actividades?</caption> <tr><td class="subtitulos">Informática y sistemas</td> <td> <input type="text" id="p074" name="p074" size="15" onkeypress="return RangoNumeroFormateado(this,0,0,event);" /></td> <td>Si <input type="radio" class="radiomarcado" id="p075" name="p075" value="1"/> No<input type="radio" class="radiomarcado" id="p075" name="p075" value="2" /></td></tr> <tr><td class="subtitulos">Investigación y desarrollo</td> <td> <input type="text" id="p076" name="p076" size="15" onkeypress="return RangoNumeroFormateado(this,0,0,event);" /></td> <td>Si <input type="radio" class="radiomarcado" id="p077" name="p077" value="1"/> No<input type="radio" class="radiomarcado" id="p077" name="p077" value="2" /></td></tr> <tr><td class="subtitulos">Ingeniería y diseño industrial</td> <td> <input type="text" id="p078" name="p078" size="15" onkeypress="return RangoNumeroFormateado(this,0,0,event);" /></td> <td>Si <input type="radio" class="radiomarcado" id="p079" name="p079" value="1"/> No<input type="radio" class="radiomarcado" id="p079" name="p079" value="2" /></td></tr> </table> </form> </body> </html> 
+4
source share
3 answers

You are using an entry point, which is used for the Class Selector (".class") . Your selector is looking for an element with a class that you don't need. You have input as a tag for which you need a Selector ("element") element , so here you should not put a dot in front of the input, nor do you assign an nsnr class to input, assign it before using it.

Edit

 $('.input[type="text"][class="nsnr"]').prop("value", "NS/NR"); 

For

 $('input[type="text"][class="nsnr"]').prop("value", "NS/NR"); 

If you assign only nsnr classes, use a simple class selector and val()

 $('.nsnr').val("NS/NR"); 
+5
source
 $('.nsnr').prop("value", "NS/NR"); 
0
source

I fixed the same problem with smt like:

 $('.nsnr').attr('value', 'NS/NR'); 
0
source

All Articles