This is a discussion on "Form Validation" within the JavaScript Forum section. This forum, and the thread "Form Validation are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Form Validation
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
Form Validation
I am writing an html form (the form handling document is written in php) and have a javascript validation document. In the form, there are 3 radio buttons and you must select one of them, if you choose the 3rd one, I want to make it compulsory that you fill in the additional information in a text field. This is the code for the section of the form:
<tr> <td colspan="4" class="fieldcell"><input type="radio" name="delivery" id="delivery_now" value="Now" tabindex="4" />Please deliver immediately</td> </tr> <tr> <td colspan="4" class="fieldcell"><input type="radio" name="delivery" id="delivery_reception" value="at the Reception" tabindex="5" />Please read out at the Wedding Reception</td> </tr> <tr> <td colspan="2" class="fieldcell"><input type="radio" name="delivery" id="delivery_other" value="Deliver Other" tabindex="6" />Other (please expand)</td> <td colspan="2" class="fieldcell"><input type="text" name="delivery_other_text" id="delivery_other_text" tabindex="7" /></td> </tr> I've got the validation working so that the user has to select a radio button, but I can't work out the code for identifying that they've selected the 3rd option and then checking that they've filled in the text box. I've attached the .js document I'm using for the validation, but I've saved it as .txt so that it uploads onto this site! Please help!! I'm fairly new to coding and this has got me stumped!!! |
|
|
|
|||
|
Re: Form Validation
You can check for the selected value by treating the radio buttons as an array and looking to see which one has been checked. As you have three button, you need something like:
Also, you cannot assume that your form has been validated client side. They may have JavaScript turned off for some reason. Validating client side is a convienience thing, you absolutely MUST validate server side as well. |
![]() |
| Tags |
| form, validation |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Form validation help! | psycho wolvesbane | JavaScript Forum | 16 | Feb 12th, 2008 16:40 |
| AS Form / Validation Help | papalazarou78 | Flash & Multimedia Forum | 0 | Jul 31st, 2007 19:43 |
| Form Validation | cjrollo | Flash & Multimedia Forum | 0 | Feb 22nd, 2007 17:33 |
| PHP Form Validation. | kaz | PHP Forum | 2 | Jul 22nd, 2006 20:47 |
| PHP Form Validation ??? | j4mes_bond25 | PHP Forum | 2 | May 31st, 2006 23:08 |