Reputation: 85
I have the following auto generated radio buttons with associated labels I would like to remove the text from the labels text and would liek to retain only the following text for each corresponding labels Approved. Reject. Pending. in the below auto generated HTML using javascript. (This html is from SharePoint approve.aspx page)
<table id="ctl00_PlaceHolderMain_approveDescription_ctl01_RadioBtnApprovalStatus" class="ms-authoringcontrols">
<tbody><tr>
<td><input id="ctl00_PlaceHolderMain_approveDescription_ctl01_RadioBtnApprovalStatus_0" type="radio" name="ctl00$PlaceHolderMain$approveDescription$ctl01$RadioBtnApprovalStatus" value="0" checked="checked">
<label for="ctl00_PlaceHolderMain_approveDescription_ctl01_RadioBtnApprovalStatus_0">Approved. This item will become visible to all users.</label></td>
</tr><tr>
<td><input id="ctl00_PlaceHolderMain_approveDescription_ctl01_RadioBtnApprovalStatus_1" type="radio" name="ctl00$PlaceHolderMain$approveDescription$ctl01$RadioBtnApprovalStatus" value="1">
<label for="ctl00_PlaceHolderMain_approveDescription_ctl01_RadioBtnApprovalStatus_1">Rejected. This item will be returned to its creator and only be visible to its creator and all users who can see draft items.</label></td>
</tr><tr>
<td><input id="ctl00_PlaceHolderMain_approveDescription_ctl01_RadioBtnApprovalStatus_2" type="radio" name="ctl00$PlaceHolderMain$approveDescription$ctl01$RadioBtnApprovalStatus" value="2">
<label for="ctl00_PlaceHolderMain_approveDescription_ctl01_RadioBtnApprovalStatus_2">Pending. This item will remain visible to its creator and all users who can see draft items.</label></td>
</tr>
</tbody></table>
Upvotes: 0
Views: 110
Reputation: 768
You need to strip the text after the "." like so:
s = s.substring(0, s.indexOf('.'));
Here's the script:
var labels = document.getElementsByTagName('label');
for (var i in labels) {
var text = labels[i].innerHTML;
if (text) labels[i].innerHTML = text.substring(0, text.indexOf('.'));
}
Here's a jsfiddle: https://jsfiddle.net/mckinleymedia/c43hjohp/1/
Upvotes: 1