Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ajax to update price based on form fields

Status
Not open for further replies.

gemma123

Programmer
Jun 16, 2010
1
GB
I am doing some work for a client at work and I am very poor at javascript and ajax.

I am working on a system that generates a very dynamic frontend. The admin can create forms on the fly and some functions generate them on the frontend. My job is to use information from these forms. I have managed to get the forms appearing on the frontend, but I need to make the price at the bottom of the form to update as the form fields are updated. Someone has suggested jQuery.

Basically, I need a javascript/ajax function that will do an onChange event for each selection that will update the price. Unfortunately I cannot target individual input fields (with an id for example) because the input fields are dynamic. I was going to create a separate php file that will calculate the new price by submitting the total value of the form at each selection and this will be accessed via ajax at the onchange event.

To further worsen the situation, the "value" of the form fields is not the price. I can get the functions that generate the price and I can sort that out with PHP. I just need the ajax calls that will update the price each time any field is changed. That is, submit the form to the price generating script. Then I can use the array that it returns to update the price. The client absolutely wants this to be ajax, no reloads. Therefore this onchange event will have to apply to all items within the form.

 
JavaScript is superb, but don't overdo it - use it wisely and don't bloat your pages.

You could search the web for individual scripts as you need them. Or you could plump for a framework like jQuery or MooTools. A framework can have a heavy filesize and limits your options somewhat but can save time and you benefit from the work of others in the community. Both approaches have pro's and con's.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top