I have very huge visualforce page.I am trying to access visualforce component in javascript.But I am getting component Id as null.How to access component Id in javascript
function createCommentForm() {
alert('Id'+document.getElementById('{!$Component.requestslist}'));
if(document.getElementById('{!$Component.newCaseComment.messag}').value == '') {
showCommentMessage('FATAL', 'Comments must be entered.');
return;
}
createComment(document.getElementById('{!$Component.newCaseComment.messag}').value,
document.getElementById('{!$Component.requestlist.request.caseId}').value );
}
function createComment(message,cId) {
Visualforce.remoting.Manager.invokeAction(
'{!$RemoteAction.RequestsController.createComment}',
message,cId,
function(){},
{escape: true}
);
}
<apex:outputPanel id="requests">
<ul class="nav nav-pills">
<li id="Open" class="active"><a onclick="changeCurrentRequestStatus('Open');">Open Requests <span class="badge">{!OpenRequestCount}</span></a></li>
<li id="Closed"><a onclick="changeCurrentRequestStatus('Closed');">Closed Requests <span class="badge">{!ClosedRequestCount}</span></a></li>
</ul>
<apex:outputPanel id="requestsList">
<div class="row">
<div class="col-md-6 col-sm-12" style="border-left: solid #DDD 1px">
<table class="table" id="tab">
<thead>
<tr>
<th>Description</th>
<th>Category</th>
<th>Location</th>
<th>Request Date</th>
</tr>
</thead>
<tbody id="tbod">
<apex:repeat value="{!Requests}" var="request">
<tr>
<td><a onclick="send('{!request.Id}')">{!request.Subject}</a><input type="Hidden" id="caseId" value="{!request.Id}"/></td>
<td>{!request.Type}</td>
<td>{!request.Location__r.Name}</td>
<td>
<apex:outputText value="{0,date,MM/dd/yyyy}" >
<apex:param value="{!request.CreatedDate}"/>
</apex:outputText>
</td>
</tr>
</apex:repeat>
</tbody>
</table>
</div>
I am trying to pass caseId as hidden element to my visualforce remote javscript
Added Page Source
<div class="col-lg-9 col-md-9 col-sm-12"><span id="j_id0:requests">
<ul class="nav nav-pills">
<li class="active" id="Open"><a onclick="changeCurrentRequestStatus('Open');">Open Requests <span class="badge">10</span></a></li>
<li id="Closed"><a onclick="changeCurrentRequestStatus('Closed');">Closed Requests <span class="badge">1</span></a></li>
<li id="Pending fix"><a onclick="changeCurrentRequestStatus('Pending fix');">Requests Pending Fix <span class="badge">0</span></a></li>
</ul><span id="j_id0:requestsList">
<div class="row">
<div class="col-md-6 col-sm-12" style="border-left: solid #DDD 1px">
<table class="table" id="tab">
<thead>
<tr>
<th>Description</th>
<th>Category</th>
<th>Location</th>
<th>Request Date</th>
</tr>
</thead>
<tbody id="tbod">
<tr>
<td><a onclick="send('500e0000002YLJkAAO')">test123</a><input id="caseId" type="Hidden" value="500e0000002YLJkAAO" /></td>
<td>Problem</td>
<td>Rosslyn</td>
<td>11/11/2013
</td>
</tr>
<tr>
<td><a onclick="send('500e0000002YLJpAAO')">test123</a><input id="caseId" type="Hidden" value="500e0000002YLJpAAO" /></td>
<td>Feature Request</td>
<td>Rosslyn</td>
<td>11/11/2013
</td>
</tr>
{!$Component.requestsList}("L" is capitalized) instead of your current version.