473,378 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

function output as form value

hi,

i've been looking for the right answer but can't seem to find it, so I figured i'd give this a try.

I'm trying to make a website where visitors can input the quantity of a certain product they want, then press a button to have a function calculate the total price of the selected products. so far I've ovly been able to get this final value in an alert box, but what I'm trying to do is to have the final price written in a textfield next to the function add button, mostly because the order eventually has to be sent to the company by mail and they would like to have the final price included.

I hope i was clear enough, if not, please comment and i'll try to make it a bit clearer(I'm 17 and english is not my native language)

thanks in advance
Stef
Apr 3 '12 #1

✓ answered by acoder

You need to access the text box and set its value, e.g.
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("text_box_id").value = total;

3 1627
acoder
16,027 Expert Mod 8TB
You need to access the text box and set its value, e.g.
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("text_box_id").value = total;
Apr 3 '12 #2
I think i was too unclear:P I meant to have the final amount to be entered into the textbox after the visitor presses the button. I'll try to simplify the code a bit(coz the total code is 161 lines...)
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script>
  4. function add(){
  5. var q1=document.myForm.productname.value;
  6. t1=q1*15.30;
  7. total=t1
  8. alert("€ "+total);}
  9. </script>
  10. </head>
  11. <body>
  12. <form name="myForm">
  13. <input type="text" name="productname">
  14. <input type="text"name="total">
  15. <input type="button" onclick="add()" value="total">
  16. </form>
  17. </body>
  18. </html>
  19.  
so what i want to do is have the total to be written in the last text box named total(maybe your code was right but i put it in the wrong spot, i just put it as last line of the add function now)

thanks
Apr 4 '12 #3
nevermind, i forgot to add the id for the textbox, but its working now, thank you very much for your help(:
Apr 4 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: J Lake | last post by:
I am working on a simple orderform script to keep a running total, however I am encountering some errors. function CalculateTotal() { var order_total = 0 // Run through all the form fields...
6
by: David | last post by:
Ok. Can PHP control a form value directly? Eg. like the javascript "document.Form1.text01.value = "Y"". Eg. allow me to put a value into a form text field on page load. Either I missed this in...
1
by: angus | last post by:
Dear All, how to try-catch "A potentially dangerous Request.Form value was detected from the client (txtUserName="<asdf")." this exception? i've set the debugger in the Page_InIt function,...
2
by: Bob Sanderson | last post by:
I have a search form from which I hope to be able to select a record by field JobNumber and display it with an output form titled test.php <html> <head> <title>Job Database Search</title>...
4
by: Tifer | last post by:
Hello, I'm still new to the whole .Net thing and I'm having a problem with something that should be so simple -- executing a query and returning an output parameter. It's a standard "Add"...
6
by: tmb | last post by:
I have a page with many dynamically created HtmlSelect controls which i create in the Page_Load function. Sometimes upon a post i need to change the selected items in some of the controls depending...
3
by: judy.j.miller | last post by:
Does anyone know why i can't access a form element value using dot notation in firefox, when i'm in a function. Works ok in the body. I'm trying to do this: var FarTemp = faren.temp.value; I...
5
by: jose1lm | last post by:
What is supposed to happen: A user enters data into one of the FORM input selections. When the user submits the form, the onclick event is supposed to go to a function that will set another FORM...
2
by: riyap | last post by:
hi can anyone let me know how to get a output param value from stored procedure i used following code to get the o/p value from stored procedure so near .value what i need to give if keep it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.