Javascript on form typing

Soldato
Joined
27 Dec 2005
Posts
17,316
Location
Bristol
I've got a basic booking form (backend PHP) to use at an exhibition. I'm looking to make everything a bit quicker and easier by implementing some Javascript.

The two main things I want to do are:

  • Add up a "cost" variable based on certain tick boxes and/or field entries.
  • Check the database if a date is taken when selected (much like username fields on various sites).

I'm an absolute novice when it comes to JS so if someone could point me in the right direction that'd be great. From these I should be able to alter them and do anything else I need.

Thanks! :)
 
Use the jQuery library to make your life (and cross-browser compabilitlity) much easier. http://jquery.com/

It provides lots of very useful functions, which should make things like checking when checkboxes are checked in very simple.

edit: you can also use the excellent jQuery Validation plug-in to have javascript error checking too.
 
Last edited:
Use the jQuery library to make your life (and cross-browser compabilitlity) much easier. http://jquery.com/

It provides lots of very useful functions, which should make things like checking when checkboxes are checked in very simple.

edit: you can also use the excellent jQuery Validation plug-in to have javascript error checking too.

Thanks - I've "installed" jQuery but I'm still none the wiser :p.
 
For the first part jQuery probably isn't needed, unless you want to read the prices for each tick box from an external source (such as XML or JSON). Something like this would probably be enough.

For the second part you'll need to use AJAX which jQuery does quite nicely.
 
For the first part jQuery probably isn't needed, unless you want to read the prices for each tick box from an external source (such as XML or JSON). Something like this would probably be enough.

For the second part you'll need to use AJAX which jQuery does quite nicely.

You could even just use the .val() in JQuery, after checking what was enetered is a number.
 
That's just it though - you'd be loading a 19k js file (assuming it isn't already cached) just to use the .val() function :)

Personally for simple form tasks I just use native js, for the fancy effects and plugins then I think it's worth using.
 
Back
Top Bottom