Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Jquery / HTML problem

Posted on 2015-02-08
2
Medium Priority
?
183 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 44

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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article discusses how to implement server side field validation and display customized error messages to the client.
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

636 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