I have got this button:
<input type="button" value="Rep"
id="rep" name="rep" class="rep" style="width:50px"
onclick="triggerLabel(1);this.disabled=true;addRep(<?php echo $comment_id; ?>);"/>
<script type="text/javascript">
function triggerLabel($commentID)
{
var $theID="#"+$commentID;
var $label=document.getElementById($theID).value;
alert($label);
}
</script>
The alert isn’t triggered. I want to obtain the commentID and convert it to a string.. And I want that string to represent my element ID. The alert works, it retrieves #25. That’s the id that I gave one of my labels..
echo '<label id="'.$comment_id.'">'.$avatarRep.'</label>';
It should retrieve that label, but unfortunately it fails..I get this:
Error: document.getElementById($theID) is null
Source File: http://localhost/PoliticalForum/Thread/thread.php?threadID=15&page=1
Line: 246
What do I do?
That’s how the label html control looks like when I view the source page:
<label id="25">6</label>
UPDATE:
I updated my answer. Take a look:
var $label=document.getElementById($commentID);
$label.value=9999;
The 9999 isnt inserted into the table..why?!?
UPDATE 2:
This doesnt work:
document.getElementById($commentID).value="88888";
The label isnt changed.
Either use
getElementByIdproperly, i.e. remove the#:or use jQuery:
Note that
labels don’t have avalueproperty. If you want to get the inner text, useinnerHTMLor.text()with jQuery.Also, before HTML5, IDs where not allowed to start with digits.