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.
Pregunta
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> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th> </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, 'ContentPlaceHolder1_rePxOffers_RejectedReasonPanel_0');">
<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('ctl00$ContentPlaceHolder1$rePxOffers$ctl01$btnUpdatePxOffer','')" id="ContentPlaceHolder1_rePxOffers_btnUpdatePxOffer_0" class="btnSubmitSmall" /></td>
<td><a id="ContentPlaceHolder1_rePxOffers_btnEmailPxOffer_0" class="btnLinkMed">Email</a></td>
<td> </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('Are you sure you want to remove this PX Offer?');" /></td>
</tr>
</table>
Solución 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.
Otros consejos
replace:
dPxOfferStatus.Attributes.Add("onchange", "RejectedShowText(this," & RejectedReasonPanel.ClientID & ");")
with:
dPxOfferStatus.Attributes.Add("onchange", "RejectedShowText(this,'" & RejectedReasonPanel.ClientID & "');")
hope it helped.