Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set input type text value by class in one line

I do a class selection by class name in radio buttons and it works Then I want to do a class selection by name in text imputs and set values to any text I could not do it

How can I do the same setting value to my text boxes

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>     
like image 367
user2269041 Avatar asked Apr 11 '13 06:04

user2269041


People also ask

Is the input type to define one line text field?

The <input type="text"> defines a single-line text field. The default width of the text field is 20 characters.

How do you put an input box on the same line in HTML?

Using table cell attribute in display property: Make a label inside a div and give the display property. To make the input element and span as equally placed use table-cell attribute in those tags. This attribute makes the element behaves a td element.

How do you make an input box a line?

To create a multi-line text input, use the HTML <textarea> tag. You can set the size of a text area using the cols and rows attributes. It is used within a form, to allow users to input text over multiple rows.


1 Answers

You are using dot with input which is used for Class Selector (“.class”). Your selector is looking for element with class input which you do not want. You have input as Tag for that you need Element Selector (“element”) so here you should not put dot before input and also you did not assign class nsnr to input, assign it before you use it.

Change

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

To

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

If you assign nsnr class to inputs only then use simple class selector and val()

$('.nsnr').val("NS/NR");  
like image 157
Adil Avatar answered Oct 18 '22 13:10

Adil