Solved

Jquery / HTML problem

Posted on 2015-02-08
2
163 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 42

Accepted Solution

by:
Chris Stanyon earned 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
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 …

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now