Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This might sound stupid..

I have this code:

switch (newcell.childNodes[1].type)
        {
            case "text":
                newcell.childNodes[1].value = "";
                break;
            case "number":
                newcell.childNodes[1].value = "";
                break;
            case "select-one":
                newcell.childNodes[1].selectedIndex = 0;
                break;

This is a little piece of code for an add/delete row functionallity I'm making. The row contains inputs.

Well, I manage to generate new raw withh all inputs except this one:

<td><input type="number" /></td>

I think the issue is here: case "number":. How do I make reference in my JS to the type="number" input?

Thank you for the help!

ADDING MORE INFO

My HTML code:

 <tbody id="dataTable">                       
                    <tr class="trBody">
                        <td>
                            <asp:DropDownList ID="FeeClass" runat="server" name="feeClass">
                                <asp:ListItem Text="" Value=""></asp:ListItem>
                            </asp:DropDownList>
                        </td>
                        <td><input type="text" value=""/></td>
                        <td><input type="number" class="numberInput" value=""/></td>
                        <td><button onclick="deleteRow(this)">Remove</button></td>
                    </tr>  
             </tbody>    

My JS code:

function addRow(dataTable) {

    var table = document.getElementById("dataTable");

    var rowCount = table.rows.length;
    var row = table.insertRow(rowCount);
    row.id = row.uniqueID;
    row.id = "row" + rowCount;
    var rowID = row.id;
    var colCount = table.rows[0].cells.length;

    for(var i = 0; i < colCount; i++) {

        var newcell = row.insertCell(i);

        newcell.innerHTML = table.rows[0].cells[i].innerHTML;
        if (i == colCount-1){
            newcell.childNodes[0].setAttribute('id', "rB" + rowCount);
        }
        newcell.childNodes[1].name = newcell.childNodes[1].id + rowCount;

        //alert(newcell.childNodes);
        switch (newcell.childNodes[1].type)
        {
            case "text":
                newcell.childNodes[1].value = "";
                break;
            case "number":
                newcell.childNodes[1].value = "";
                break;
            case "select-one":
                newcell.childNodes[1].selectedIndex = 0;
                break;
        }
    }
    event.preventDefault();
}

It generates the new row and stops at the number input. Genrates the dropdown, the text input and stops...

share|improve this question

1 Answer 1

use typeof(newcell.childNodes[1]) instead newcell.childNodes[1].type

share|improve this answer
    
I will try it. (Having some problems with server at the moment). I just updated post with more info if needed. –  SrAxi Jun 19 at 13:51
    
I tried, and didn't work. I mean, it works with text inputs, but didn't work with the number input.. Maybe is stopping there of some other reason. But the same script is working for another table (with same id number and structure but without number input). –  SrAxi Jun 19 at 13:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.