简体   繁体   中英

Can't run PHP with JavaScript eventlistener

Im using PHP to create a canvas to write and it will output text as result to a textarea(done by other functions). There are some other input tag too such as title etc to get input from users. The value/content from these input tag (title and textarea) will submit to the database with form method "post". However i have some buttons with event listener function attached for the canvas part ("undo" or "redo" strokes). The saving part already successful been done but the event listener part seems to not working, each time i press undo or redo the window will load like my submit button and my canvas wont undo or redo the strokes and i'm not sure what is wrong with the code, anyone can help me? The example of code is something as below:

<body>
<form method="something.php" method="post">
<label for = "datetime">Date Created:</label><br>
<input type="text" name="inputDate" size="20" disabled>   //disabled because i put timestamp
<input type= "submit" name = "submit" value="Save"></input>
<pre><textarea id="result" name = "res"></textarea></pre>    //the text will output here
</form>
<br><canvas id="myCanvas" width="400" height="400"></canvas><br>   //where my i draw
<button id="undo" class = "button" >Undo</button>
</body>

<script>
(function () 
{
var undo = document.getElementById('undo');
..
..
 undo.addEventListener('click', function () 
{
if (!inkRecog.isEmpty()) 
{
inkRecog.undo();    
}
doRecog();
},
 false);
 })();
</script>

my inkRecog.undo already declare in another form, previously working, but when i put the form method in the body it won't work.

//

You need to

return false;

at the end of the event listener under doRecog();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM