質問

Within a repeater each row has a dropdown. If the user selects a 'rejected' from the dropdown I want a textbox to appear so they can enter some text.

The javascript error i'm getting is: Error: TypeError: RejectedReasonBox is 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';
        }

    }

So it seems that its not getting the id value for RejectedReasonId but the generated html looks fine:

 onchange="RejectedShowText(this,ContentPlaceHolder1_rePxOffers_RejectedReasonPanel_0);"

CODE BEHIND

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

I had the textbox i wanted to display with a DIV wrapped around it, the DIV was hidden and i was trying to show/hide this.

I'm not sure why this was causing the issue but I managed to fix it by removing the DIV and just show/hiding the textbox.

他のヒント

replace:

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

with:

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

hope it helped.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top