returning strings to other parts of a form

  You are currently not logged in. You can view the forums, but cannot post messages. Log In | Register

31-May-09 18:10
as I am learning to work with the Document Object Model, and creating variables to do simple math problems, I am not having any luck figuring out how to return the result of a math function to a specific field or form element on the page.

Lets say, for the sake of clarity, that I have a varialbe called "itemPrice", and I have a variable called "quantity".
Adn finally I have a variable called "total" which wil basically show the result of the multiplication of the itemPrice times the quantity.
var total = itemPrice*quantity

Now the problem or question I am having is how to get the result of that, which is the total contained in the variable named total, to transfer to an element some where else on the form page, so that when I select an item and then choose the quantity I can actually see the total in a box or an element field on the form page.

I guess My question is, how do I get the string from the variable called "total" to appear in a form element on the web page?

Andy help with what i am sure is probably a very simple problem, would be greatly appreciated.

joe_s_watson@hotmail.com

31-May-09 23:44
Hi Joe,

To set a form field's value, use the "value" property, eg:

document.getElementById('formFieldId').value = total;

--
Matt Doyle, Elated
3rd Edition of my jQuery Mobile book out now! Learn to build mobile web apps. Free sample chapter: http://store.elated.com/

 
New posts
Old posts

Follow Elated