Prevents the form,link from being submitted more then once

เวลา double click ที่ link, form ทำให้มันทำงานซ้ำซ้อนหลายครั้งอีกทั้ง javascript ยังทำงานแบบ asynchronous method ทำให้ค่าผิดพลาดได้ จึงต้องเขียนป้องกันการ double click ดังตัวอย่าง

...
<script type="text/javascript">

var requestSubmitted = false;
       function submitRequest() {
              if (!requestSubmitted ) {
                     requestSubmitted  = true;
                     return true;
              }
              return false;
       }

</script>
...
<form action="Logon" method="POST" onsubmit="javascript:submitRequest()">
......
</form>

credit:http://publib.boulder.ibm.com/infocenter/wchelp/v5r6/index.jsp?topic=/com.ibm.commerce.developer.doc/refs/rcsdblclickclientside.htm

About WK

Kajook is a Senior Software Engineer. Job is Design & Develop in Java EE environment on Glassfish. I'm Interested in Agile software development ,iOS and Android.
This entry was posted in ploblem and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s