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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:41:03+00:00 2026-05-24T01:41:03+00:00

I am trying to fill in a form using Javascript/ajax/php but the problem is

  • 0

I am trying to fill in a form using Javascript/ajax/php but the problem is that my function only fills in one of the needed forms and stops even tho I have gotten the second response from the server.

Code:

The function that starts filling stuff

function luePankkiviivakoodi(str) {
if (str==null) { //are we NOT injecting variables directly into the code, if not - Prompt for the barcode, and set the variable
    var str = prompt("Valmis vastaanottamaan", "");
}
if (str==null) { //someone pressed abort on the prompt, we return
    return;
}
newstr = str.split(' ').join(''); // remove spaces
if (str=="") { //is the string empty? -> return
    return;
}
if (window.XMLHttpRequest) { //AJAX code
    xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        eval(xmlhttp.responseText);
        //we set some fields, no problem
        document.getElementById('P_VII').value = viite;
        document.getElementById('IBAN').value = saajatili;
        document.getElementById('laskun_summa').value = summa;
        document.getElementById('eräpäivä').value = eräpäivä;
        //trigger other functions
        getKassasumma(summa); //AJAX for accesing the database and calculating the sale price
        DevideIntoCells(); //AJAX for accessing the database and dividing a sum into different cells
        validateSumma(); //Validates the sum, and tells the user if it's OK
    }
}
xmlhttp.open("GET","dataminer.php?question=pankkiviivakoodi&q="+newstr,true);//open AJAX connecttion
xmlhttp.send();//send stuff by AJAX

}

getKassasumma:

function getKassasumma(str) {
if (str=="") {
    return;
}
 if (window.XMLHttpRequest) {
    xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4 && xmlhttp.status==200) {
        eval(xmlhttp.responseText);
    }
}
kale = document.getElementById("TOS_K_ale").value;
xmlhttp.open("GET","dataminer.php?question=kassasumma&q="+str+"&kale="+kale.replace("%", "p")+"&nro="+document.getElementById("S_NRO").value,true);
xmlhttp.send();
}

DevideIntoCells:

function DevideIntoCells() {
    str = document.getElementById('tiliöintitapa').value;
    if (str==null) {
            return;
    }
    if (window.XMLHttpRequest) {
        xmlhttp=new XMLHttpRequest();
        document.getElementById("spinwheel3").style.visibility = "visible";
    }
    xmlhttp.onreadystatechange=function() {
        //alert('OK! val= '+xmlhttp.readyState);
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
            //alert('OK!');
            eval(xmlhttp.responseText);
            //alert('OK2!');
            document.getElementById("spinwheel3").style.visibility = "hidden";
            //alert('OK3!');
            calculateSumma();
        }
    }
    xmlhttp.open("GET","dataminer.php?question=percentages&q="+str+"&nro="+document.getElementById('S_NRO').value,true);
    xmlhttp.send();
}

validateSumma (just some math):

function validateSumma() {
    float = document.getElementById('summabox').value;
    float = float.replace(",",".");
    summa = parseFloat(float);
    if (summa < 0) {
        summa = 0
    };
    kassasummaunp = document.getElementById('laskun_summa').value;
    kassasummafloat = kassasummaunp.replace(",",".");
    kassasumma = parseFloat(kassasummafloat);
    if (kassasumma < 0) {
        kassasumma = 0
    };
    if (kassasumma == 0 || summa == 0) {
        prosentti = "0%";
    }
    else {
        prosentti = summa / kassasumma * 100;
        prosentti = Math.round(prosentti*Math.pow(10,2))/Math.pow(10,2);
        prosentti = prosentti+"%";
    };
    if (prosentti == "100%") {
        is100 = 1;
    }else {
        is100 = 0;
    }
    document.getElementById('prosentti').innerHTML = prosentti;
    if (is100 == 1) {
        document.getElementById('prosentti').setAttribute("style", "color:green");
    } else {
        document.getElementById('prosentti').setAttribute("style", "color:red");
    }
    puuttuvaEuro();
}

The problem code here is getKassasumma(summa); and DevideIntoCells();. I disable one of them, and the other one works, I enable both of them, DevideIntoCells stops somewhere before document.getElementById(“spinwheel3”).style.visibility = “hidden”;, probably at the eval(response) because getKassasumma already finished the ajax request and killed this one. same the other way around.

AJAX answers: DevideIntoCells:

var KP_osuus = parseFloat('40');
laskunsumma = parseFloat(document.getElementById('laskun_summa').value);
onepercent = laskunsumma/100;
newvalue = onepercent*KP_osuus;
document.getElementById('box1.5').value = newvalue;
var KP_osuus = parseFloat('60');
laskunsumma = parseFloat(document.getElementById('laskun_summa').value);
onepercent = laskunsumma/100;
newvalue = onepercent*KP_osuus;
document.getElementById('box2.5').value = newvalue;

AJAX answer: getKassasumma

var kassasumma = '477.99€';
document.getElementById('kassasumma').value = kassasumma;

Please ask if you need clarification!

EDIT: Just to be clear, this is NOT an AJAX problem, rather javascript.

  • 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-24T01:41:03+00:00Added an answer on May 24, 2026 at 1:41 am

    Try to make xmlhttp local, i.e.

    var xmlhttp;
    

    Because you are overwriting you xmlhttp you refer to in the event listeners, so when the listeners get called, they both see the same response.

    at the beginning of every of your functions. For compatibility, also use send(null) instead of send().

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

Sidebar

Related Questions

I am trying to fill a form in a php application from a C#
I'm trying to fill-out a form automatically and press a button on that form
I'm trying to dynamically fill a form in Python using Mechanize. However, when I
I'm trying to load fragments of XHTML markup using jQuery's $.fn.load function, but it
i'm trying to code an application for Android that fills up a form in
Hey all I am trying to fill a html form using a java program
I'm trying to renew my company intranet using jquery, ajax and php. General aspect
I am trying to auto fill a form (currently using contact form 7) with
I am trying to do multiple product add with a form using php and
I am trying to fill object[] with List<string> but I cannot figure out how

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.