Not sure what is the right approach to tackle this

I want to control te textarea Reason based on what is selected in the dropdown list. As you can see below i have got to the stage where i can get the attribute id of each row of the DropDown list Status But i can't get the attr id of each textarea Reason

My final result should be if a user selects declined then the user but enter a reason and if deactivated must enter a date. Thanks in advance

<td class="ms-vb"><span dir="none">
<select class="ms-RadioText" title="Status" id="WebPartManager_g_31f0d9e1_72a0_4ef2_b286_7c30cd0fda1f_ff5_3_ctl00_DropDownChoice" name="WebPartManager$g_31f0d9e1_72a0_4ef2_b286_7c30cd0fda1f$ff5_3$ctl00$DropDownChoice">
<option value="Provisionally Approved" selected="selected">Provisionally Approved
<option value="Approved">Approved</option>
<option value="Declined">Declined</option>
<option value="Deactivated">Deactivated</option>
<td class="ms-vb">
<span dir="none">
<textarea dir="none" class="ms-long" title="Reason" id="WebPartManager_g_31f0d9e1_72a0_4ef2_b286_7c30cd0fda1f_ff11_3_ctl00_ctl00_TextField" cols="20" rows="6" name="WebPartManager$g_31f0d9e1_72a0_4ef2_b286_7c30cd0fda1f$ff11_3$ctl00$ctl00$TextField" style="display: none;">Test3</textarea><br>




 $("tr select[title='Status']").change(function () {

        var selectedValue = $(this).find("option:selected").text();

        if (selectedValue == 'Declined')

       alert('You need to type in a Reason if STATUS is DECLINED!');

        //i'm getting the id of each dropdown row here
        var select_id = $(this).attr('id');  
        var b = $("#" + select_id).text();
        //i can get the id of each Dropdown  of each row

         //i'm getting the id of each textarea row here
        var textarea_id = $("tr td textarea").attr('id'); 
        var c = $("#" + textarea_id).text();

        //i'm only getting the attr id of the first textarea but not the other


        if (selectedValue == 'Deactivated')

        alert('You need to select a De-Activated Date if STATUS IS DEACTIVATED!');


I am not quite sure where is your problem. From HTML markup you provided there is only one textarea on your page. I am also not sure why you need Id.

You can easily reference desired text area utilizing title attribute:


and if you really need id then:


Like I said, it is not quite clear what are you trying to achieve (well, it is, but HTML markup is most likely incomplete) so if this doesn't solve your problem please let me know.

  • Sorry Vedran i taught when i wrote "For each row" you would understand that there are multiple rows involved so imagine the markup i posted having multiple rows but the id of the dropdown and the textarea would be incrementing.Hope you understand why i need the id now.Chrs and thanks alot
    – naijacoder
    Jul 29 '11 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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