Home › Forums › JavaScript › Collecting form data to display elsewhere on page?
- This topic is empty.
-
AuthorPosts
-
November 29, 2010 at 4:00 pm #30844
scottgm
MemberHi there,
Ive got a collection of forms all with check boxes, its basically a coffee menu with four sections.
Say for example the user selects (clicks check box) a small cappuccino, a latte, and an espresso, how can i get the input names (name+size of coffee) to appear with the value (cost of coffee) in another div so i can then calculate sub-total, add vat etc
So far ive only managed to get the users selections to appear where i want using jQuery serialize, however im having a little trouble picking out the values to carry out calculations on them.
Can anyone suggest an easier / better way for me to approach this?
note : this is a made up project for a fake client and cant involve any server side scripting.
November 30, 2010 at 1:47 pm #71689cybershot
Participantserver side scripting would be the way to go for any project like this. If you use javascript then your form is subject to fail anytime anyone has javascript turned off. Your form will not work. This is bad web design. I would recommend that you use php. it is the best and easiest way to go. Getting the information is really easy using php. There are many form tutorials using php. Why don’t you want to use server side scripting?
November 30, 2010 at 3:43 pm #71679scottgm
Memberyeh i totally understand that, but this project is for a uni assignment, part one to only use client side technologies, part two is where these are changed out to server side.
November 30, 2010 at 3:51 pm #71652TT_Mark
MemberHave you tried using JSON? You can set up a multidimensional array of data that stores everything you need, then when the user selects something, simply utilise JQuery to get the appropriate corresponding price etc.
November 30, 2010 at 9:23 pm #71657scottgm
Memberhi mark, any chance you could explain that a bit more, im fairly new to javascript so just getting used to the basics.
heres what i currently have, http://www.scottgm.co.uk/test
from here i need to be able to target the users selection to perform calculations for vat, delivery etc.
Thanks
December 2, 2010 at 8:09 pm #71290scottgm
MemberI’ve managed to come up with a solution (im implementing at the moment), it involves separating the huge string of info and converting the cost of the coffees to a float where i can perform the calculations i need (Vat etc), and of course using css to position everything where it needs to be.
I realise now i should have created an associative array or something similar for the coffee menu then pulled the users choice, similar to what mark suggested above, however im fairly new to javascript so just picking up things as i go.
Thanks all for the help :)
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.