Hello I am in desperate need of some help. I'm building a dvd store website and I want to add a javascript component. A form that uses javascript and submits form data (ie shopping cart information) to a processing script. The form must submit using the post method and have the following properties: A visible unit price to 2 decimal places for the product or service A hidden form field where a product code for this item is stored (can be "p1" for example) A quantity field allowing only a positive integer which represents the number of items being ordered. A customer can enter the amount directly A minus()and a plus(+)button that updates the quantity field by1unit A submit button (can be called "Add" or "Buy" etc) The form won't submit if the quantity field is not a positive integer. I have no idea how to even start this so if anyone can help me that would be fantastic. Cheers.
Well, your first step is to make it work WITHOUT JavaScript FIRST! There are two reasons for this, both play to the unwritten rule of JS -- "If you can't make a page work without scripting first, you probably have no business adding scripting to it." The first is accessibility and graceful degradation. A LOT of people flat out don't trust JS and browse with it blocked; mobile users will block it since it chews on their batteries for no good reason, etc, etc... The second is far, FAR more important; SECURITY. The base rule of building a form is that ALL user input is suspect. Someone bypasses your form with a bot, or starts forcing submits and plugging values in randomly, you NEED to recheck that all the values are valid server-side. Of course, if you're checking all the values server-side, you do question if using scripting client-side isn't a wee bit redundant... Though unlike a lot of cases I'd say your concept is viable -- the trick being to make it workable without scripting first, then enhance it. Just remember you should NEVER trust your client-side validation to actually work. Before going further I'd have to ask -- what's your skill level on this? How's your HTML skills? Do you understand how get/post actually work and how to make a normal non-scripted form? Are you familiar with using scripting to hook onto elements and create your scripting only elements? Where you are at on skill level greatly impacts how doing this should be explained. ... unless you want me to start at complete nube level. (which I can do...)