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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:06:59+00:00 2026-06-10T16:06:59+00:00

I am passing data using J-Query and AJAX to res.php page:- attempt.php (my main

  • 0

I am passing data using J-Query and AJAX to res.php page:-

attempt.php (my main page from where the res.php is called)

$.ajax(
                    {

                        url: "res.php", 
                        type: "POST",
                        data: data,     
                        success: function (data) 
                        {
                            var build_id='build_';
                            build_id += i;
                            alert(build_id);
                            $('#npc').append(data);
                            $('#build_id').attr('disabled','true');
                            var total = $("#build_id");
                            alert(total);
                        }
                    });

In the res.php page I am using the passed data to generate the query and retrieve data from the database and calculated the total value and display the total in a text box.

res.php

$i = mysql_real_escape_string($_POST['i']);

$query = "select * from ";
$query = $query . $building;
$query = $query . " where lvl=" . $level;
$query = $query . ";";

$result = mysql_query($query) or die('Error in Child Table!');
echo $i;
while( $data = mysql_fetch_assoc($result))
{
$total_res = $data['lumber'] + $data['clay'] + $data['iron'] + $data['crop'];
echo '<tr><td>'. $building. '</td><td>'. $level. '</td><td><input type="text" style="width:70px" id="build_' . $i . '" value="' . $total_res . '"></td></tr>';
}

I am using id="build_' . $i . '" to auto increment the id of the text box. Till here everything goes fine.

Back to the attampt.php page,
when I try to access the data from the text box i am unable to access it.

The code that I’m using to access the data is:-

                            var build_id='build_';
                            build_id += i;
                            $('#build_id').attr('disabled','true');
                            var total = $("#build_id");
                            alert(total);

the alert function at the end of the code gives the following output:-

[object Object]

I am trying to append a list of text boxes with some values to a table and then calculate the sum of all the values in the text boxes.
Please 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-06-10T16:07:00+00:00Added an answer on June 10, 2026 at 4:07 pm

    $('#build_id') should be $('#'+build_id) and to calculate the total of all the values, you should put var total=0; outside your callback function, and the function should contain

    total += $('#'+build_id).val(); 
    

    Another problem is that each row of the table has the same id="build_$i", but IDs have to be unique.

    And do you really intend to display $i at the beginning of the table, without it being in a table row?

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

Sidebar

Related Questions

i have problem passing data from one page to another using GET, for example
I am trying to edit a data query using php by passing it through
passing post data using cURL requires that the name of the input. However, I
i have data structure i am passing this from server to client using data
Currently I'm using AudioTrack passing to it audio data from native layer to play.
I've recently faced a problem involving passing data (small amount), from a page to
I am using WCF data services to 'query' for data models from my web
I am using ajax in my jsp page to get all the values from
I am getting values from mysql data base using get method i am passing
I'm passing data between my controller and my view using a ViewModel class. When

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.