在中繼器中,每行都有一個下拉列表。如果用戶從下拉菜單中選擇「拒絕」,我想要一個文本框出現,以便他們可以輸入一些文本。顯示文本框onchange asp.net
的JavaScript錯誤我得到的是: 錯誤:類型錯誤:RejectedReasonBox是空
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> </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>
嗨,謝謝,試過這個答案,仍然得到相同的錯誤。 – JBoom
現在生成的html看起來如何? – geevee
onchange =「RejectedShowText(this,'ContentPlaceHolder1_rePxOffers_RejectedReasonPanel_0');」 – JBoom