SherryG
asked on
Making form fields required
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?
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?
yes you can using javascript
Take a look on the following example
https://www.experts-exchange.com/questions/20401581/validate-radio-buttons.html
https://www.experts-exchange.com/questions/20401581/validate-radio-buttons.html
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.">
say you radiobutton named "aaa"
then make just another input
<INPUT TYPE="hidden"
NAME="aaa_required"
VALUE="Please, select your favorite color.">
<!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.txtOthe rs.value == ""){
alert("Specify the other")
document.testform.txtOther s.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 <input type="Text" name="txtOthers" value="">
<br><input type="button" name="btncheck" value="check" onclick="fncheck()" >
</form>
</body>
</html>
<html>
<head>
<title>Untitled</title>
<script language="JavaScript">
function fncheck(){
if ( document.testform.rdcolor[
if (document.testform.txtOthe
alert("Specify the other")
document.testform.txtOther
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 <input type="Text" name="txtOthers" value="">
<br><input type="button" name="btncheck" value="check" onclick="fncheck()" >
</form>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.