Form Validation

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.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 3rd, 2006, 09:47
New Member
Join Date: Aug 2006
Location: UK
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
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!!!
Attached Files
File Type: txt validate.txt (2.1 KB, 18 views)
Reply With Quote

  #2 (permalink)  
Old Aug 3rd, 2006, 16:12
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Skype™ to ukgeoff
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:

Code: Select all
for (i = 0; i <= 2; i++)
{
   if (document.myForm.delivery[i].checked) && (i == 2)
   {
      code to check for mandatory field
   }
}
Note that the array is 0 based.

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.
Reply With Quote
Reply

Tags
form, validation

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT. The time now is 19:43.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43