?
Solved

Jquery / HTML problem

Posted on 2015-02-08
2
Medium Priority
?
189 Views
Last Modified: 2015-02-08
Hello,

See following Jquery

<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script type="text/javascript" src="jquery/jquery.lightbox_me.js"></script>
      
<script>
            
                  $(document).ready(function() {
                  
                        $('#button').click(function(e) {
                              $('#as_built').lightbox_me({
                                    closeClick:      true,      
                              });
                              e.preventDefault();
                        });                        

                  });
$(function() {
    $( "#adddate" ).datepicker();
    $( "#datecompl" ).datepicker();
      $("#cleardc").on('click',function () {
            $.datepicker._clearDate("#datecompl");
      });      
      $("#clearal").on('click',function () {
            $.datepicker._clearDate("#adddate");
      });      
});
</script>

This html:

<tr>
            <td align="right">Date Completed:&nbsp;</td>
            <td><input name="datecompl" id="datecompl" type="text" class="pt12" size="12" readonly="readonly">&nbsp;<button id="cleardc">Clear date</button></td>
      </tr>

When the Clear Date button is clicked, it clears the date but submits the form.

Why does it submit the form? Is the button element considered a submit element?
0
Comment
Question by:Richard Korts
2 Comments
 
LVL 45

Accepted Solution

by:
Chris Stanyon earned 2000 total points
ID: 40597337
You'll need to prevent the default behaviour of the button. You can do this with the preventDefault() method of the function's argument - e in the example below:

$("#cleardc").on('click',function (e) {
   e.preventDefault();
   $.datepicker._clearDate("#datecompl");
});

Open in new window

0
 

Author Closing Comment

by:Richard Korts
ID: 40597419
Excellent!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question