I want to use javascript in my custom Joomla content plugin, but I can't get my custom text when type text in my input by using getElementById
.
My code is:
<?php
$output = '
<input type="text" id="name" value="default" />
<button onclick="myAlert();" >test code</button>
<script>
var myText = document.getElementById("name").value;
function myAlert(){
alert(myText);
}
</script>
';
?>
When I click the button only alert default value and not my custom name.
How can I do this?