Hey there :) I'm trying to make a function so when composing text, user can click button that fetch random value from array and put in textarea no refresh. My current problem is once page load, it get the random value from array in php and js using onclick, but clicking the button dont get new value, always the same until refresh.
I'm not very JS I only use php and some ajax/jquery refresh call. Here my actual function and codes:
function randommacro(){
$randomword = array(1, 2, 3, 4, 5);
//$randomword = file('macro/randomword.txt');
shuffle($randomword);
$randomword = $randomword[0];
return $randomword;
}
<script language="javascript" type="text/javascript">
function addtext(text) {
document.myform.message.value += text;
}
</script>
<button class="btn btn-primary" onclick="addtext('<?php echo htmlspecialchars(randommacro()); ?>'); return false">Random Macro</button>