Cancel a form to be submitted, do not change the data of the entity

I have a div

   <div id="updateChoice%s" class="text-center"></div>

which shows a the following upon a “updateText” button is clicked

function updateText(urlsafe) {
    document.getElementById("updateChoice"+urlsafe).innerHTML +=
    '<br><br><form id="dynForm" action="/updateText" method="post" >' +
   '<textarea name="newContent" rows="5" cols="80"></textarea>' + 
   '<input type="hidden" name="update" value=' + urlsafe + '>' +   '<br><br>' + 
   '<input class="choice" type="submit" value="Submit"></input> <button class="choice"  onclick="cancelUpdate('+ urlsafe +')">Cancel</button>' +

I want to cancel the updating of the text but it doesn’t work unless “newContent” is empty, here is /updateText file and cancelUpdate(urlsafe)


class UpdateText(webapp2.RequestHandler):
     def post(self):
         greeting_key = ndb.Key(urlsafe=self.request.get('update'))
         event = greeting_key.get(); 
         if(self.request.get('newContent') != ''):
           event.content = self.request.get('newContent');


function cancelUpdate(urlsafe) {

any ideas?

Source: forms

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.