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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:09:04+00:00 2026-05-27T09:09:04+00:00

I’m trying to call a php function from jquery function to calculate some values

  • 0

I’m trying to call a php function from jquery function to calculate some values and store them the values in session and list the values that are stored in session. I’m passing the values to jquery function from html form on mouse click event. And i’m using the fallowing code to achieve this.

This is the HTML form code in one php file name totalprice.php:

<table width="100%" >
<tr>
          <td >type</td>
          <td><select name="costtype" id="costype">
      <option>one time</option>\n<option>multi</option>\n
      </select></td></tr>

        <tr>
          <td  align="right">destination </td>
          <td>  <select name="destination" id ="destination"><option>Lagos</option>\n<option>Oyo</option>\n<option>Kano</option>\n<option>Rivers</option>\n<option>Edo</option>\n<option>Ogun</option>\n<option>Kaduna</option>\n<option>Plateau</option>\n<option>Anambra</option>\n<option>Delta</option></select></td>
        </tr>

        <tr>
          <td  align="right">Total eight (Kg) </td>
          <td><input type="text" size="10" name="weight" id="weight"></td>
        </tr>

        <tr>
          <td>&nbsp;</td>
            <td><input type="submit" value="Submit"     onclick="javascript:calculate()" name="caliculate" class="button"></td>
        </tr>
      </tbody></table>

      <div id="testtable">cal value will be displayed here.</div>
</form>

And this is the jquery function

  function calculate() {

    var costtype = $("#costype").val();
    var destination = $("#destination").val();
    var totalweight = $("#weight").val();


    xmlhttp=new XMLHttpRequest();

    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==0)
        {
        document.getElementById("testtable").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("POST","caltest.php?item="+escape(costtype)+"&totalweight="+escape(totalweight)+"&destination"+escape(destination),true);
    xmlhttp.send();

  }

This is caltest.php file where i’m doing the calculation and displaying the session data By using the table

$itemtype = urldecode($_POST['item']);
$destination = urldecode($_POST['destination']);
$totalweight = urldecode($_POST['totalweight']);

$sql        = "select price from prices_list where  lower(costtype)='".strtolower($itemtype )."' ";

$price=0;
$Result         = mysql_query($sql) ;

 while ($row = mysql_fetch_array( $Result))
{
$price     = (isset($row['price'])) ? $row['price'] : "";
 }

$price = round($price,2);

$costcharges = $price*$totalweight;
$costtcharges = round($costcharges,2);

Here i’m doing some code to store the data into session
$fee_details=$test_fee->storetestfee($itemtype,$totalweight,$destination,$costcharges);

 echo "<table width='75%' >
        <tbody><tr>
         <th width='2%' class='highlight'><b>#</b></th>
          <th width='30%' class='highlight'><b>Item </b></th>
          <th width='23%' class='highlight'><b>Destination</b></th>
          <th width='5%' class='highlight'><b>weight (Kg) </b></th>
          <th width='10%' class='highlight'><b>cost Charge</b></th>
        </tr>";
 if(count($fee_details)>0)
 {$i=0;
    foreach($fee_details as $key=>$test_price)
    {$i++;
    echo " <tr>  ";
    echo "<td>".$i."</td>";
    echo "<td>".$test_price['item_type']."</td>";
    echo "<td>".$test_price['destination']."</td>";
    echo "<td>".$test_price['totalweight']."</td>";
    echo "<td>".$courier_details['weightcharges']."</td>";
    echo " </tr>  ";
}}
echo "</tbody>
 </table>";

This code is perfectly working when i worked directly with out using jquery. I want this to be done without refreshing the page. Can any out help out where i’m doing mistake in the code, Please. Thank you.

  • 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-27T09:09:04+00:00Added an answer on May 27, 2026 at 9:09 am

    the first off all, you don’t have to use xmlhttp=new XMLHttpRequest(); when using jquery, jquery has a function to do that, just use load, post or ajax, may be this one can help you

    $(function(){
        $("input[type=submit]").click(function(){
            var costtype = $("#costype").val();
            var destination = $("#destination").val();
            var totalweight = $("#weight").val();
    
            $.ajax({
                type    :'POST',
                url     :"caltest.php?item="+escape(costtype)+"&totalweight="+escape(totalweight)+"&destination"+escape(destination),
                success :function(result){
                    //action where request complete, result come from server
                }
            });
        )};
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.