Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

85
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!