显示文本框onchange asp.net

时间:2013-10-17 11:59:19

标签: javascript asp.net repeater asp.net-4.0

在转发器中,每行都有一个下拉列表。如果用户从下拉列表中选择“已拒绝”,我希望显示一个文本框,以便他们输入一些文字。

我得到的javascript错误是: 错误:TypeError:RejectedReasonBox为null

JAVASCRIPT

function RejectedShowText(sel, RejectedReasonId) {

        var RejectedReasonBox = document.getElementById(RejectedReasonId);

        window.alert(RejectedReasonId);

        if ( sel.options[sel.selectedIndex].value == 'Rejected' ) {

            RejectedReasonBox.style.display = '';
        }
        else {
                        RejectedReasonBox.style.display = 'none';
        }

    }

所以它似乎没有得到RejectedReasonId的id值,但生成的html看起来很好:

 onchange="RejectedShowText(this,ContentPlaceHolder1_rePxOffers_RejectedReasonPanel_0);"

代码背后

dPxOfferStatus.Attributes.Add("onchange", "RejectedShowText(this," & RejectedReasonPanel.ClientID & ");")

HTML

<div id="PxOfferDetails">


            <table style="width: 100%;" class="dataInput dataInputBorder" cellpadding="0" cellspacing="0">
                <tr>
                    <th>Offer (£)</th>
                    <th>Offer (%)</th>
                    <th>Date</th>
                    <th>Offer Expiry</th>
                    <th>Extended</th>
                    <th>Offer Status</th>
                    <th>&nbsp;</th>
                    <th>&nbsp;</th>
                    <th>&nbsp;</th>
                    <th>&nbsp;</th>
                    <th>&nbsp;</th>
                    <th>&nbsp;</th>
                </tr>

                <tr>
                    <td><span id="ContentPlaceHolder1_rePxOffers_lPxOfferAmount_0">£110,000.00</span></td>
                    <td><span id="ContentPlaceHolder1_rePxOffers_lPxOfferPercent_0">84.62</span></td>
                    <td><span id="ContentPlaceHolder1_rePxOffers_lPxOfferDate_0">26/02/2013</span></td>
                    <td><span id="ContentPlaceHolder1_rePxOffers_lPxOfferExpiry_0">05/03/2013</span></td>
                    <td><input name="ctl00$ContentPlaceHolder1$rePxOffers$ctl01$tPxOfferExtended" type="text" id="ContentPlaceHolder1_rePxOffers_tPxOfferExtended_0" class="date" /></td>
                    <td><select name="ctl00$ContentPlaceHolder1$rePxOffers$ctl01$dPxOfferStatus" id="ContentPlaceHolder1_rePxOffers_dPxOfferStatus_0" class="small" onchange="RejectedShowText(this, &#39;ContentPlaceHolder1_rePxOffers_RejectedReasonPanel_0&#39;);">
    <option selected="selected" value="Awaiting Decision">Awaiting Decision</option>
    <option value="Accepted">Accepted</option>
    <option value="Rejected">Rejected</option>

</select>

                        <div id="ContentPlaceHolder1_rePxOffers_RejectedReasonPanel_0" style="display:none;">

                            <input name="ctl00$ContentPlaceHolder1$rePxOffers$ctl01$tPxRejectedReason" type="text" size="20" id="ContentPlaceHolder1_rePxOffers_tPxRejectedReason_0" />

</div>
                    </td>
                    <td></td>
                    <td><a id="ContentPlaceHolder1_rePxOffers_btnRecreatePxOffer_0" class="btnLinkMed">Recreate</a></td>
                    <td><input type="button" name="ctl00$ContentPlaceHolder1$rePxOffers$ctl01$btnUpdatePxOffer" value="Update" onclick="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolder1$rePxOffers$ctl01$btnUpdatePxOffer&#39;,&#39;&#39;)" id="ContentPlaceHolder1_rePxOffers_btnUpdatePxOffer_0" class="btnSubmitSmall" /></td>
                    <td><a id="ContentPlaceHolder1_rePxOffers_btnEmailPxOffer_0" class="btnLinkMed">Email</a></td>
                    <td>&nbsp;</td>
                    <td><input type="image" name="ctl00$ContentPlaceHolder1$rePxOffers$ctl01$btnDeletePxOffer" id="ContentPlaceHolder1_rePxOffers_btnDeletePxOffer_0" title="Remove PX Offer" class="btnDelete" src="images/icon-delete.png" onclick="return confirm(&#39;Are you sure you want to remove this PX Offer?&#39;);" /></td>
                </tr>

            </table>

2 个答案:

答案 0 :(得分:0)

取代:

dPxOfferStatus.Attributes.Add("onchange", "RejectedShowText(this," & RejectedReasonPanel.ClientID & ");")

使用:

dPxOfferStatus.Attributes.Add("onchange", "RejectedShowText(this,'" & RejectedReasonPanel.ClientID & "');")
希望它有所帮助。

答案 1 :(得分:0)

我有一个文本框,我想用DIV环绕它显示,DIV被隐藏,我试图显示/隐藏它。

我不确定为什么会导致此问题,但我设法通过删除DIV并显示/隐藏文本框来修复它。