Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6927245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:01:37+00:00 2026-05-27T11:01:37+00:00

Hello I have a page displaying jquery datepicker and based on the datepicker a

  • 0

Hello I have a page displaying jquery datepicker and based on the datepicker a fetch and show custom form:

            <div id="datepicker"></div>
            <script type="application/javascript">
                function fetch_form (date_string, inst) {
                    var date = $('#datepicker').datepicker('getDate');
                    var date_list = [date.getFullYear(), date.getMonth() + 1, date.getDate()];
                    var url = "/luncher/by_date/" + date_list.join("/");    

                    $.ajax({
                        url: url,
                        cache: false,
                        success: function(html){
                            $("#form-container").html(html);
                          }
                        });

                    ajax_form();
                }

                function ajax_form () {
                    $("#food_form").ready(function(){
                        $("#food_form").submit(function(e){
                            alert(e);
                          });
                    });
                }

                $('#datepicker').datepicker({
                     firstDay: 1,
                     onSelect: fetch_form, 
                     });
                now = new Date();
                fetch_form(now);
            </script>
        </div>
        <div class="span6" id="form-container">
        </div>

The problem is that I need to set custom .submit function for fetched form, I have tried that in ajax_form function, but the form is ignoring my customization and the form is submitted in normal way.

Here is sample form being fetched:

<h1>Dishes for Dec. 15, 2011</h1>
<form id="food_form" action="/luncher/by_date/2011/12/15" method="post"> 
    <div style='display:none'><input type='hidden' name='csrfmiddlewaretoken' value='9ba228bab1a61b993eba4180f2a2237e' /></div>
    <table>
        <tr><th></th><th>Dish:</th><th>Enjoyed?</th><th>More often?</th></tr>

            <tr><td>Lunch</td><td><select name="lunch" id="id_lunch">
<option value="55">Vinná klobáska s bramborovou kaší</option>

<option value="56">Filety s koprovou omáčkou</option>
<option value="57">Dukátové buchtičky</option>
</select></td><td><input type="checkbox" name="lunch_taste" id="id_lunch_taste" /></td><td><input type="checkbox" name="lunch_preference" id="id_lunch_preference" /></td></tr>


            <tr><td>Soup</td><td><select name="soup" id="id_soup">
<option value="53">Zeleninový vývar</option>
<option value="54">Bramborová</option>
</select></td><td><input type="checkbox" name="soup_taste" id="id_soup_taste" /></td><td><input type="checkbox" name="soup_preference" id="id_soup_preference" /></td></tr>


            <tr><td>Dinner</td><td><select name="dinner" id="id_dinner">
<option value="58">Kuřecí nudličky gyros s tzatzikami</option>

<option value="59">Sýrové těstoviny</option>
</select></td><td><input type="checkbox" name="dinner_taste" id="id_dinner_taste" /></td><td><input type="checkbox" name="dinner_preference" id="id_dinner_preference" /></td></tr>

    </table>

Thanks for any help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:01:37+00:00Added an answer on May 27, 2026 at 11:01 am
    $('#form-container').on('submit', '#food_form', function () {
        //custom code here
    });
    

    Using .on() like this is similar to .delegate() where we:

    Attach a handler to events for all elements that match the selector, now or in the future,
    based on a specific set of root elements

    Source: http://api.jquery.com/delegate/

    Another solution is to attach the event handler when the form is inserted into the DOM:

                    $.ajax({ 
                        url: url, 
                        cache: false, 
                        success: function(html){ 
                            $("#form-container").html(html);
                            $('#food_form').on('submit', function () {
                                //custom code here
                            });
                          } 
                        }); 
    

    Using .on() like this is similar to .bind() where the element must be present in the DOM when the call is made.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have page like this <html> <head> <div id=container> Hello, this is NON-IE content.
Hello i have a JSP page that contain a form, i want to validate
Hello I have a page with some jquery ui tabs on it and they
Hello I have some javascript code, a script included inside my page. I want
I have such a link in JSP page with encoding big5 http://hello/world?name=婀ㄉ And when
Hello we have an SQL server application running over a low bandwith connection. We
Hello i have this form filling javascript: function onLine(code,nn) { document.writeform.bericht.value+=code; document.writeform.bericht.focus(); document.writeform.nickname.value+=nn; write1();
hello i have a problem that's maybe difficult to descripe, i have an application,
Hello mates i have a page View All Applicants.aspx with gridview and a link
I have page part like this <div id=inbox> <h1>Headline</h1> <p>First paragraph</p> <table> <tbody> <tr>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.