javascript - Populate function return value into element -
javascript - Populate function return value into <input> element -
i writing chat page site. have managed getmyfunction()
inquire user name welcome 'username'. problem utilize same name within name input box chat itself, rather user having input name every single time wish write message. have used onclick=
prompt user name cannot display name within name box.
<form action='submit.php' method='post' name='form'> name:<br><p>click button demonstrate prompt box.</p> <button onclick="myfunction()">try it</button> <p id="demo"></p> <script> function myfunction() { var person = prompt("please come in name", "harry potter"); if (person != null) { document.getelementbyid("demo").innerhtml = "hello " + person + "! how today?"; } } </script> name: <br> <input type='text' name='name' size='20' onclick='myfunction()'><br> message:<br> <textarea name='message' cols='40' rows='2'></textarea><br>
edit: have since discovered whilst javascript code in submit.php, submit.php not display @ :/
you should clarify happens, should happen, , want happen. you've told, take want alter input's value name user entered through prompt dialog. in case, do:
<script> function myfunction() { var person = prompt("please come in name", "harry potter"); if (person) { document.getelementbyid("demo").innerhtml = "hello " + person + "! how today?"; document.getelementbyid("name").value = person; } } </script>
by way, not part of question, when have input field entering username, asking through prompt dialog doesn't create sense. inquire user come in through input field, , whenever it's changed (onchanged
property of <input>
element), handle script.
javascript html function input onclick
Comments
Post a Comment