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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:47:43+00:00 2026-06-03T19:47:43+00:00

So I have a link on my page Add Shipping Point. This brings up

  • 0

So I have a link on my page “Add Shipping Point”. This brings up a dialogue, which has the user enter some information .. when the user then clicks “Save Shipping Point” the dialogue closes and javascript adds a new row on the screen.

Problem is, if the user then clicks the checkbox on the dynamically created row and clicks “Delete Shipping Point” the row is not deleted.

This is occuring because the code that creates the new row does so before the AJAX calls which does the db update returns with the proper id.

So I need to get the code to wait for the id before creating the row. I see similar problems here on Stack, but the syntax of the calls is a bit different so I’m not sure how to get it to apply to my situation.

Here is the code from the dialogue that calls the save and creates the new row.

if (bValid) {
// make Ajax call save the Shipping Point and add to the list
var shipPointId = saveShippingPoint();                  

    // This alert when active does not have the id.
    //alert("Alert3:" + shipPointId);

if (shipPointId == "na") 
    {
        alert("There was a problem adding the Shipping Point.  Please try again.  If the problem persists please contact support.");
} 
    else 
    {
    $j("#shipPoints tr:last").after(
              "<tr>" 
            + "<td>" + city.val().toUpperCase() + ", " + state.val().toUpperCase() + "</td>" 
            + "<td>"
            + "<INPUT type='checkbox' NAME='chk' VALUE='"+ shipPointId + "' />"
            + "<INPUT type='hidden' NAME='shipPointId' VALUE='"+ shipPointId + "' />"
    + "</td>"+ "</tr>");
}
$j(this).dialog("close");
}

And this is the code which makes the AJAX call for the save….I put a while loop in there to force the wait just as a temp change to confirm that this is the issue … with the loop it waits, and the row is created correctly. Without the function immediately returns an unvalued id to the caller and it does not work. So need to know the proper way to get it to wait so I get the behavior I need.

// Ajax call to add the Shipping Point to the Session
function saveShippingPoint() {

    var savedId = "";

    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
        if(xhr.readyState == 4) {
            savedId = xhr.responseText;
        }

    };      
    var url = '<portlet:resourceURL id="saveShippingPoint"/>';
    xhr.open("GET", url + 
       "?city=" + $j( "#city" ).val().toUpperCase() +
       "&state=" + $j( "#state" ).val().toUpperCase() +
       "&stateOther=" + $j( "#stateOther" ).val().toUpperCase() +
       "&zip=" + $j( "#zip" ).val() +
       "&product=" + $j( "#product" ).val().toUpperCase()
       , true);
    xhr.send();

    /* WHile loop just here to test and verify problem */
    while(xhr.readyState != 4) /* null statement */ ;       
    return savedId;
}

Thanks in advance,
-Jim

Ok, based off the first few suggestions I have modified the code so that instead of manipulating the XmlHttpRequest myself I use $.ajax and define the success callback method.

Being new to jquery, I’ve clearly messed up some syntax here, as the Add Shipping Point button is no closing and not adding the row …

Here is the new code:

$j("#dialog-form").dialog(
{
    autoOpen : false,
    height : 500,
    width : 500,
    modal : true,
    buttons :
    {
        "Add Shipping Point" : function()
        {
            var bValid = true;
            var cityValid = true;
            var stateValid = true;
            var zipPresent = true;
            var zipValid = true;
            updateTips("");
            allFields.removeClass("ui-state-error");
            cityValid = checkRequired(city, "City");
            stateValid = checkRequired(state, "State");
            zipPresent = checkRequired(zip, "Zip");
            if(zipPresent) { zipValid = checkRegexp(zip, /(^\d{5}$)|(^\d{5}-\d{4}$)/, "Zip Code"); }
            bValid = cityValid && stateValid && zipPresent && zipValid;
            if (bValid)
            {
                saveShippingPoint();
                $j(this).dialog("close");
            }
        },
        Cancel : function()
        {
           $j(this).dialog("close");
        }
    },
    close : function()
    {
        allFields.val("").removeClass("ui-state-error");
    }
});
$j("#add-shipping-point").click(function()
{
    $j("#dialog-form").dialog("open");
    return false;
});
});
</script>
<script>
// Ajax call to add the Shipping Point to the Session
function saveShippingPoint()
{
$.ajax(
{
// This is a portal URL....which in reality has no spaces, it just didn't paste in very nicely
url: "/web/secure/!ut/p    /b1/jY7LUoMwGIWfpQ_g5CekGJdRKHek3FrYdCLN0DgUKlBUnl7sxpXo2Z2Z71xQgXIMVAVMASjao6Lho6z4INuG19--0A7xo51uEs1x9Sx- AntNrMAgBMBUZiCfAUUJXd81FaDPAGD7DnYjfa0A4P_l4Rcx- Cu_Q8UNWXpwAxYmAqs9C5TP2P3PVOJjHWxPswjoRAWKUYL2QA7xK30bjsb79bOcQiC0n_pqPMKH46bt4DUvnke7bFKzNGNbFuhGNLHVar6ZL5fvOt3164UKOr5KOKTvFxkU4WtbAa0LXl5Ep4YRR3ySqBzUW8e7DtznBj7Ao0UMN4!/" +
"?city=" + $j( "#city" ).val().toUpperCase() +
"&state=" + $j( "#state" ).val().toUpperCase() +
"&stateOther=" + $j( "#stateOther" ).val().toUpperCase() +
"&zip=" + $j( "#zip" ).val() +
"&product=" + $j( "#product" ).val().toUpperCase() ,
type: 'GET',
cache: false,
timeout: 30000,
success: function(data)
{
$j("#shipPoints tr:last").after(
"<tr>"
+ "<td>"
+ city.val().toUpperCase()
+ ", "
+ state.val().toUpperCase()
+ "</td>"
+ "<td>"
+ "<INPUT type='checkbox' NAME='chk' VALUE='"+ data + "' />"
+ "<INPUT type='hidden' NAME='shipPointId' VALUE='"+ data + "' />"
+ "</td>"
+ "</tr>");
}
});
return;
};
</script> 
  • 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-06-03T19:47:45+00:00Added an answer on June 3, 2026 at 7:47 pm

    Change your saveShippingPoint function to use the jQuery Ajax functions (rather than constructing and using the xhr object yourself) then implement a success callback to update your table.

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

Sidebar

Related Questions

i have a command link in my page which looks like: <h:commandLink value=Add user
I'm trying to add column to ASPxGridView which would have link to other page:
On this page I have a link to a google map which opens in
I have been using the following to add a dynamic link on a page
I have a link to a page which invokes the 'Sexy Alert Box' script
I have a link_tag in view which add rendered content to page link_to("add",nil,:id=>"create_row_cycle",:onclick=>"$('div#cycle_form table').append('#{escape_javascript(render(:partial=>'cycles',
I have a link in a page which I am using for print the
I have a link with a title attribute on a HTML page. Since this
I have a link in a page that goes like this: Url.Action(List, Item, new
i have this link which when clicked a modal dialog box will appear. <a

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.