tags:

views:

80

answers:

3

Hello, I have a table, has many rows. for example one of from rows(all rows are same):

             <tr>
                <td>
                    <input type="text" />
                </td>
                <td>
                    <textarea cols="40" rows="3" ></textarea>
                </td>
                <td>
                    <select id="chbTypes11">
                        //options
                    </select>
                </td>
                <td>
                    <input type="text" />
                </td>
                <td>
                    <input type="checkbox" />
                </td>
            </tr>

select element is disabled by default. How to determine, input value has value? for enabling select element in this row

+3  A: 

If by 'input' you mean any kind of input element other than a select, then:

$("tr input, tr textarea").change(function() {
    var $select = $(this).closest("tr")
                         .find("td > select");
    $select.attr("disabled", !($.trim(this.value).length > 0));
});

// IE and checkbox change events don't like each other
$("tr :checkbox").click(function() {
    $(this).closest("tr").find("td > select")
                         .attr("disabled", !$(this).is(":checked"));
});

If you're only referring to the textbox, just change the selector to $("tr input:text")

karim79
Oh, I like this, that's a nice answer.
Plynx
+1 but you forgot the else that disables it again if the input box is cleared ;-)
Andy E
thanks, for absolute answer.
loviji
+1  A: 

You retrieve the value with $(...).val() but this isn't enough to solve your problem. You need to know what to put in for the .... Since these <input> elements might be dynamically generated you might want to do it based on some kind of event (i.e. on the change event of the input box), or if they are server generated, give them IDs that correspond with the other elements in that row to make things easier on yourself.

Plynx
I use for dynamically added rows $("tr input:text").live('change', function() {//});
loviji
A: 
$('tr:has(td input[value!=""])')

(or close to that)

The [value!=""] should match all non-empty value attributes.

CWF
`input[value]` by itself is enough for matching non-empty values.
karim79