Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Making form fields required

Posted on 2003-03-17
5
Medium Priority
?
132 Views
Last Modified: 2013-12-24
I have a form with textfields and radio buttons(groups).  For instance....


What is your favorite color  
a. red (radio)  
b. blue (radio)  
c. green (radio)
d. other (radio)-please specify _______________ (text)


I want to make the entire question required, so the user must select atleast one of the radio buttons and if they select (d) I want to also make the text field required.

I have many questions like this on my form.

Any suggestions?

0
Comment
Question by:SherryG
5 Comments
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 8154961
yes you can using javascript
0
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 8154989
0
 
LVL 1

Expert Comment

by:Wasistdas
ID: 8156344
not necesserily javascript:

say you radiobutton named "aaa"

then make just another input
<INPUT TYPE="hidden"
    NAME="aaa_required"
    VALUE="Please, select your favorite color.">
0
 
LVL 6

Expert Comment

by:dash420
ID: 8157786
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
     <title>Untitled</title>
<script language="JavaScript">
      function fncheck(){
         if ( document.testform.rdcolor[3].checked){
             if (document.testform.txtOthers.value == ""){
               alert("Specify the other")
                document.testform.txtOthers.focus()
                return false
             }
          }  
         
      }  
</script>    

</head>

<body>
<form name="testform">
   <br><input type="Radio" name="rdcolor" checked>Red
   <br><input type="Radio" name="rdcolor">Blue
   <br><input type="Radio" name="rdcolor">Green
   <br><input type="Radio" name="rdcolor">Other &nbsp;<input type="Text" name="txtOthers" value="">
   <br><input type="button" name="btncheck" value="check" onclick="fncheck()" >
</form>



</body>
</html>
0
 
LVL 17

Accepted Solution

by:
anandkp earned 100 total points
ID: 8164324
u need to use both javascript & server side checks for validating ur form

the user may disable the javscript & then jsut to make sure u have everything correct - have server side checks as well

K'Rgds
Anand
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month13 days, 7 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question