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 6559459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:19:48+00:00 2026-05-25T13:19:48+00:00

I have this fsField is the class of all elements in the form. So

  • 0

I have this

“fsField” is the class of all elements in the form. So whenever the user blurs to another field it submits the form using the function autosave() – given below. It saves data when the user blurs but when the user clicks the button with class “save_secL” to go to next page it does not save.

$('.fsField').bind('blur', function()
 {
autosave();
 }

 });

but when i use this code

$('.save_secL').click(function()
{
 var buttonid = this.id;
{

                    var answer = confirm("You have left some questions unanswered. Click OK if you are sure to leave this section? \\n Click CANCEL if you want stay in this section. ");
    if(!answer)
    {
    var spl_items = valid().split(',');
    $(spl_items[0]).focus();

return false;
  }
else
{
        $('#hidden_agree').append('<input id="secLuseragreed" name="secL_user_agreed" value="unanswered" type="hidden" />');
    autosave();
    window.location= buttonid+".php"
        }
    }
    else
    {
    $('#hidden_agree').append('<input id="secLuseragreed" name="secL_user_agreed" value="answered all" type="hidden" />');
    autosave();
    window.location= buttonid+".php"
    }
}
  });

**autosave_secL.php is the php source thats saving the data in the database. I ran it independently and it does save data okay. **

function autosave()
{
var secL_partA_ques_1_select = $('[name="secL_partA_ques_1_select"]').val();
var secL_partA_ques_1 = $('[name="secL_partA_ques_1"]:checked').val();
var secL_partA_ques_2_select = $('[name="secL_partA_ques_2_select"]').val();


$.ajax(
    {
    type: "POST",
    url: "autosave_secL.php",
    data: "secL_partA_ques_1_select=" + secL_partA_ques_1_select + "&secL_partA_ques_1=" + secL_partA_ques_1 + "&user_id=<?php echo $row_token[user_id]?>" + "&updated_by=<?php echo $member."-".$key;?>",
        cache: false,
    success: function()
    {    
    $("#timestamp").empty().append('Data Saved Successfully!');
    }

    });

}

**

valid() is a validation function that checks if any field is empty and returns a value if there is an empty field.**

 function valid()
{

    var items = '';
    $('.fsField').each(function() 
    {

        var thisname = $(this).attr('name')
        if($(this).is('select'))
        {
            if($(this).val()=='')
            {
                var thisid = $(this).attr('id')
                items += "#\"+thisid+\",";
                $('[name=\"'+thisname+'\"]').closest('td').css('background-color', '#B5EAAA');
            }
        }
        else
        {
            $('[name=\"'+thisname+'\"]').closest('td').css('background-color', '');
        }
    });

    return items;
}

Can anyone please help? i am stuck for a day now. Can’t understand why it saves when the user goes field to field but does not save when button is clicked with validation.
Tested with Firefox. this line appears in red with a Cross sign beside when the button(save_secL class) is clicked. I am using a ssl connection.

POST https://example.com/files/autosave_secL.php   x

Here is the modified code trying to implement the solution

$('#submit_survey_secL').click(function()
{

    if(valid() !='')
    {
         var answer = confirm("You have left some questions unanswered. Are you sure you want to Submit and go to Section B? ");
         if(!answer)
        {
               var spl_items = valid().split(',');
               $(spl_items[0]).focus();

               return false;
        }
          else
        {
            $('#hidden_agree').append('<input id=\"secLuseragreed\" name=\"secL_user_agreed\" value=\"unanswered\" type=\"hidden\" />');

            autosave(function(){
                window.location= "part1secM.php?token=1&id=4"
            });
        }
    }
    else
    {
        $('#hidden_agree').append('<input id=\"secLuseragreed\" name=\"secL_user_agreed\" value=\"unanswered\" type=\"hidden\" />');

        autosave(function(){
            window.location= "part1secM.php?token=1&id=6"
        });
    }
});


function autosave(callback)
{

    var secL_partL_ques_1_select = $('[name="secL_partL_ques_1_select"]').val();
    var secL_partL_ques_1 = $('[name="secL_partL_ques_1"]:checked').val();
    var secL_partL_ques_2_select = $('[name="secL_partL_ques_2_select"]').val();


    $.ajax(
    {

    type: "POST",
    url: "autosave_secL.php",
    data: "secL_partL_ques_1_select=" + secL_partL_ques_1_select + "&secL_partL_ques_1=" + secL_partL_ques_1 + "&user_id=<?php echo $row_token[user_id]?>" + "&updated_by=<?php echo $member."-".$key;?>",
        cache: false,
    success: function()
        {    
             $("#timestamp").empty().append('Data Saved Successfully!');

                     if($.isFunction(callback))
         {                  
            callback();
         }
        }

    });

}

I don’t understand why this doesn’t work as callback should totally work. Firebug does not show POST https://example.com/files/autosave_secL.php in red any more but it shows that it has posted but I think the callback is not triggering for some reason

  • 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-25T13:19:48+00:00Added an answer on May 25, 2026 at 1:19 pm
    $('.save_secL').click(function() {
    
    //...
    
    //start autosave. Note: Async, returns immediately
    autosave();
    //and now, before the POST request has been completed, we change location...
    window.location= buttonid+".php?token=$row_token[survey_token]&$member=$key&agr=1"
    //....and the POST request gets aborted :(
    

    Solution:

    function autosave(callback)
    {
    //...
    $.ajax(
        {
    //...
        success: function()
        {    
            $("#timestamp").empty().append('Data Saved Successfully!');
            if($.isFunction(callback)) 
                callback();
        }
        });
    }
    
    //and
    
    autosave(function(){
        window.location= buttonid+".php?token=$row_token[survey_token]&$member=$key&agr=1"
    });    
    

    By the way, your autosave function is pretty hard for your server. Did you consider using localStorage + a final POST request containing all data?

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

Sidebar

Related Questions

I have this form: <%= form_tag posts_path, :method => :get, :class => search_nav do
I have this class class Validator implements iValidation{ protected $_fields, $_errors; public function __construct($fields){
i have this function that transforms image to trapezoid using PHP GD: function perspective($i,$gradient=0.9,$rightdown=true,$background=0xFFFFFF)
I have this form, in which i need to populate a combo box with
I have this function // add history paths and save data function AddPath( strTag,
I have this class: Class B { private String D; private String E; }
Have this in Global.asax using windsor 2.5.1.0 _windsor.Register( Component.For<IViewEngine>().ImplementedBy<RazorViewEngine>(), ); When executing this right
Have have this line of code in my form when I create a new
i have this js bookmarklet that makes all the current page's font colors black.
I have this line: <xsl:when test=document('foo.xml')/field_config/field_rename/field[@old_name = $name]/@new_name> foo.xml: <field_config> <field_rename> <field old_name=Modified new_name=modification/>

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.