?
Solved

Jquery / HTML problem

Posted on 2015-02-08
2
Medium Priority
?
177 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

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

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
This article discusses how to create an extensible mechanism for linked drop downs.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

800 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