Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I pass an amount variable from within a website page inside javascript to an outside var in the html for posting to paypal?

Posted on 2006-06-26
6
Medium Priority
?
267 Views
Last Modified: 2013-12-16
Hi everyone,


I have some javascript in a webpage which calculates the total amount of selections on the page.  I need to somehow pass this variable "TotalAmt" to the html area of the page to be then posted to paypal.  The problem is that once the javascript block ends so does the variable etc.

Can anyone help?

Please let me express my thanks in advance.

Best regards,

Dynotoe
0
Comment
Question by:Dynotoe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:maUru
ID: 16989055
got some code?
0
 
LVL 7

Expert Comment

by:maUru
ID: 16989069
i dont know if this will work since i have no context but:

// this is the html form box that contains the value to be posted
<input type="text" id="totalamt" name="totalamt">


// this is the javascript that goes *directly under* the line (in the javascript) where TotalAmt is finally calculated
  document.forms[0]..value = TotalAmt;
0
 
LVL 7

Expert Comment

by:maUru
ID: 16989072
sorry that should read:

 document.forms[0].totalamt.value = TotalAmt;
0
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 
LVL 3

Expert Comment

by:boethius78
ID: 16990511
Not sure how a javascript question ended up in the C# area, but can't you just use something like this:

var totalAmount;

function calculateAmount()
{
    totalAmount = Math.random();
}


Depends on how you want to pass the variable on.  If you'll be using Javascript (eg: XMLHttpRequest), this approach will be fine.  If you'll be using HTTP POST, I'd suggest using a hidden input control (ie: <input type="hidden" id="totalAmount" />) and using document.getElementById('totalAmount').value = ... to set the value.
0
 

Author Comment

by:Dynotoe
ID: 16995620
Hi Gents,

Boethius,  I implemented what you suggested and wrote the following to see if it was working and it is.

//document.write(grosstotal);
//document.write(grandtotal);
document.getElementById('totalamount').value = grandtotal;
var text=document.getElementById('totalamount').value;
document.write(text);

}//end of javascript

However I can't seem to get the value into the paypal amount line in the html area further down on the page for posting...

<input type="hidden" name="amount" value="">

where this would normally work...

<input type="hidden" name="amount" value="400.00">


Please Help!!  :)

Best Dynotoe
0
 
LVL 3

Accepted Solution

by:
boethius78 earned 2000 total points
ID: 16999269
I'm not totally sure that I've understood your question, so please forgive me if I'm off target.

You'll need to add an id to the element in order to access it easily from javascript:

<input type="hidden" id="amount" name="amount" />

Once you've called document.getElementById('amount').value = grandtotal;, the value will be set correctly.  The HTML source, however, won't display the changed value.  Essentially, the HTML is used to load the page into it's initial state.  After that, the form and all of it's values are held in memory.  When you submit the page, the value recieved by the server will be correct, but the HTML won't have been altered.

Hope this helps.
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question