?
Solved

Making form fields required

Posted on 2003-03-17
5
Medium Priority
?
130 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

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 …
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

800 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