I’m using javascript to get my element id value. But out of 3, one of my element id does not parse in. It gives me [object HTMLInputElement] while the rest of element id values can work.
Sample Code:
<?php
$Name = "Johnnnny";
echo "<input type=\"hidden\" name=\"Name\" id=\"Name\" value=\"$Name\"/>";
?>
<script>
var ID= document.getElementById('ID').value; //this works.
var Name = document.getElementById('Name').value; //give me [object HTMLInputElement]
</script>
Kindly advise. It should be able to get the ElementID of ‘Name’.value
You should put your
<input>element inside a<form>You seem to have your ids confused. Getting an ElementById returns a DOM element that has an id attribute set to the value you’ve supplied.
so if I have something like this:
doing something like this:
would return the form and this:
would return the hidden input. Now you can access the attributes of the hidden input like this:
iname.value[returns the value] oriname.name[returns the name]Additionally, like stated by somebody else this cannot be all of your code, because
document.getElementById('ID')would return nothing (null) and you would get an error.