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

  • Home
  • SEARCH
  • 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 8033965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:52:10+00:00 2026-06-05T01:52:10+00:00

I have a javascript method which is doing some calculation. At the end, I

  • 0

I have a javascript method which is doing some calculation. At the end, I want to store it in a hidden field. Here is the method:

<script>
function getQuantity(){
 var count = document.getElementById('hidden').value;
 var Quantity=new Array();
 var i=0;
 for(i=0; i<count; i++)
 {
    Quantity[i]=document.getElementById(i).value;
 }
var myJSONQuantity = JSON.stringify(Quantity,'');
alert(myJSONQuantity);

document.qForm.getElementById('hdnQuantityArray').value = myJSONQuantity;
alert(document.qForm.getElementById('hdnQuantityArray').value);
}
</script>

I have checked here, everything is working fine. The last alert is printing the correct value.
Here is the form, in which there is a button, for which I want to submit fields on submit through method GET:

<form  name="qForm" method="GET" action="CalculateTotal.php">
    <input type="hidden" id="hdnQuantityArray" name="hdnQuantityArray">
    <input type="submit" value="CheckOut" id="CheckOut" name="CheckOut">
</form>

My query string shows:

http://localhost/blazorange/Customer/CalculateTotal.php?hdnQuantityArray=&CheckOut=Submit

I want this hdnQuantityArray to have some value in query string.

P.S. this javascript method is called from another form’s submit button in the same file. And this form is a PHP form.
Here is the code for the other form’s submit button:

<input type="submit" value=" Total " id="total" onClick="return getQuantity()">

EDIT:

<table border=1>
    <form id="CartForm">    
        <tr>
            <td>
                <h2> <font color='Grey'>Item Name</font> </h2>
            </td>
            <td>
                        <h2> <font color='Grey'>Item Price</font> </h2>
            </td>
            <td>
                    <h2> <font color='Grey'>Quantity</font> </h2>
            </td>
        </tr>
    <?PHP

        /*     Displaying the total and purchased cart's items    */

            $j=0;
            $temp=new Item();
            while(isset($ItemsArray[$j])) {
        ?>
        <tr>
                        <?PHP

                    if (is_string($ItemsArray[$j])) {
                $temp=unserialize($ItemsArray[$j]);
                 }

                $ItemName=$temp->getItemName();
                $Price=$temp->getPrice();
            ?>

            <td>
                <font color='Black'><?PHP echo $ItemName; ?>
            </td>

            <td>
                <font color='Black'><?PHP echo $Price;  ?></font>
            </td>

            <td>
                <input type="text" id="<?PHP echo $j;?>"/> 
            </td>
            </tr>


        <?PHP $j++; }?>


        <table>
            <input type="button" value=" Total " id="total" onClick="getQuantity()">
            <input type="hidden" value="<?PHP echo $j; ?>" id="hidden">

        </form>
    </table>
  • 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-05T01:52:12+00:00Added an answer on June 5, 2026 at 1:52 am

    document.getElementById('hidden')

    should be

    document.getElementById('hdnQuantityArray')

    There’s no element with an id of “hidden” in the code you posted.

    EDIT:

    You’re saying the JS only runs when the CartForm is submitted? That reloads the page, right? When the page reloads, hdnQuantityArray is empty. So when you submit qForm, there’s nothing there, because the page loaded with a blank field, and the JS didn’t run again. Does that sound right?

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

Sidebar

Related Questions

I have a JavaScript function which redirect to Asp.net MVC action method. [AcceptVerbs(HttpVerbs.Post)] public
I have one method in my managed bean which returns javascript as a string.
I have the following javascript method: function 123_test_function(){ } The function is generated by
I have a Javascript function that is called from the onchange method in a
I have a problem when call applet method from javascript.. I used this function
I want a main object M containing a sub-object S which has some method
Doing some client-side JavaScript development, which requires me to call a client-side API which
I have a javascript method looks like this JSMethod(JS_para_1,JS_para_2) { ...... ,,,,, } and
i have a javascript method that takes a date: convert(new Date(02/20/2010); how can i
I call window.location.reload(false) in a javascript method to update the page. I have additional

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.