Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

83
Vistas
jquery .find() to search for one of two different values

I have a table and I am making it editable. On double click on a cell I make the cell editable and clicking outside I revert it with the updated value.

tableCells.dblclick(function() {
    cell=$(this)
    value=cell.text();
    editing=true;
    rowIndex = cell.parent().index('table tbody tr');
    tdIndex = cell.index('table tbody tr:eq('+rowIndex+') td');
    switch(tdIndex) {
        case 1:
        case 2:
        case 9:
            cell.html('<input type="text" value="'+value+'">');
        break;
        case 3:
            cell.html('<select name="dob" id="dob" class="form-control"><option value="1">Uomo</option><option value="2">Donna</option></select>');
            break;
        case 4:
            let temp = value.split('/');
            value=temp[2]+'-'+temp[1]+'-'+temp[0];
            cell.html('<input type="date" value="'+value+'">');
        break;
    }
});
$(document).click(function(e) { //se clicco fuori dalla tabella
    if(editing){
        if (!tableCells.toArray().some(f => f.contains(e.target))) {
            let row = cell.parent('tr').data('row'); //la riga da aggiornare nel db
            updValue=cell.find('input').val();
            if(e.target.cellIndex==4){
                let temp=updValue.split('-');
                updValue=temp[2]+'/'+temp[1]+'/'+temp[0];
            }
            
            console.log(updValue);
            console.log('riga '+row);
            cell.html(updValue);
            editing = false;
        }

    }
})

this updValue=cell.find('input').val(); works fine for the fields where I have an input. But in one situation I replace the cell with a select. How can I add the select situation to this code in the lightest way? I will always have only input or select only editing the table. In pseudocode I'd say .find('input'||'select'). I don't want to have to add a class or a name attribute but to keep searching for the tag type (input or select)

I have tried with .find('input','select') but i get undefined this way

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can add classes to those inputs/selects and then cell.find('.myInput') or use this, assume you have name attribute cell.find('[name]')

Or else the solution is: cell.find('select, input')

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda