|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
#1
|
||||
|
||||
|
Validating Radio Button Groups with JavaScript
Code:
<script language="JavaScript">
function Validate(frm, btnName)
{
var btn = frm[btnName]
var valid
for (var x = 0;x < btn.length; x++)
{
valid = btn[x].checked
if (valid) {break}
}
if(!valid)
{
alert("Please select an answer.")
}
}
</script>
<body>
<form>
<input type="radio" name="question1" id="1b1" value="1">Always</input>
<input type="radio" name="question1" id="1b2" value="2">Often</input>
<input type="radio" name="question1" id="1b3" value="3">Sometimes</input>
<input type="radio" name="question1" id="1b4" value="4">Rarely</input>
<input type="radio" name="question1" id="1b5" value="5">Never</input>
<div>
<input type="button" value="Submit Answer" onClick="Validate(this.form, 'question1')"/>
</div>
</form>
</body>
|
|
#2
|
||||
|
||||
|
Validating Radio Button Groups with JavaScript
Just found this an ARC.... but my question is what changes whould I need to do if I want a submit button to do the same test?
cheers for any help..... |
|
#3
|
||||
|
||||
|
try this
Code:
<Form onSubmit="Validate(this.form, 'question1')"> |
|
#4
|
||||
|
||||
|
Validating Radio Button Groups with JavaScript
yea I tried that and got the following error:
Line: 17 Error: 'undefined' is null or not an object Line: 17 being for (var x = 0;x < btn.length; x++) as I haven't got a input type of button i'm using submit otherwise the form does not go to the next page. |
|
#5
|
||||
|
||||
|
post your code.
btn is just the name of the radio group. |
|
#6
|
||||
|
||||
|
Validating Radio Button Groups with JavaScript
<%@ Language=VBScript %>
<HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> <link rel="STYLESHEET" type="text/css" href="scripts/sgstyle3.css" /> <script language="JavaScript"> function Validate(frm, btnName) { var btn = frm[btnName] var valid for (var x = 0;x < btn.length; x++) { valid = btn[x].checked if (valid) {break} } if(!valid) { alert("Please select an answer.") } return true; } </script> </HEAD> <BODY> <!--<P> </P>--> <% set cn = server.CreateObject ("adodb.connection") cn.Open "dsn=dbAID;" set rs = server.CreateObject ("adodb.recordset") StrSql = "SELECT NAME, COMPANY, PHONE, fldCustomerID, NOTES FROM tblCustomers" _ & " WHERE (((tblCustomers.CALLSTATUS)=" & Request("calls") & ") AND ((tblCustomers.PHONE) Is Not Null))" _ & " AND (((tblCustomers.CALLBACKDATE)IS NULL))" _ & " OR (((tblCustomers.CALLSTATUS)=" & Request("calls") & ") AND ((tblCustomers.PHONE) Is Not Null))" _ & " AND (((tblCustomers.CALLBACKDATE)<=#" & Date() & "#))" rs.Open StrSql,cn if rs.EOF then Response.Write "Their are no calls waiting in Calls " & Request("calls") & "." else Response.Write "<font color=purple size=5><b>" & rs("COMPANY") & "</b> " & rs("PHONE") & "<br>" if FormatDateTime(Now(),4) >="12:00:00" then%> <font color="purple" size="5"> Good Afternoon, <%else%> <font color="purple" size="5"> Good Morning, <%end if if rs("NAME") ="" then Response.Write "please may I speak to the person who deals with you Chrismas Card ordering." else Response.Write "please may I speak to </font><font color=red size=5>" & rs("NAME") & "</font><font color=purple size=5>.</font>" end if Response.Write "<form name=yes action=callscript2.asp?calls=" & request("calls") & "&custid=" & rs("fldCustomerID") & "&customer=yes method=post>" Response.Write "<input type=submit value=YES>" Response.Write "</form><hr color=purple width=565 align=left>" Response.Write "<font size=3>If <b>NO</b> then please select one of the following reasons:" %><form name="no" action="processcallscript.asp?calls=<%=Request("calls")%>&custid=<%=rs("fldCustomerID")%>&customer=no" method="post" onSubmit="Validate(this.form, 'noanswer')"> <table> <tr> <td> <input type="radio" value="1" id="1b1" name="noanswer">No Answer</td> <td> </td> </tr> <tr> <td><input type="radio" value="2" id="1b2" name="noanswer">Not In</td> <td><font color="red">Ring Back (DD/MM/YYYY): </font><input type="text" name="ringback" size="20"></td> </tr> <tr> <td><input type="radio" value="3" id="1b3" name="noanswer">Has Left</td> <td><font color="red">New Contact: </font><input type="text" name="newperson" size="40"></td> </tr> <tr> <td colspan=2>Please enter note below:<br><textarea id="specialnotes" name="notes" rows="4" cols="50"><%=rs("NOTES")%></textarea></td> </tr> <tr><% ' onClick="Validate(this.form, 'noanswer')" %><td colspan=2><input type="submit" value=" NO "></td><% Response.Write "</tr>" Response.Write "</table>" Response.Write "</form>" rs.Close cn.Close set rs = nothing set cn = nothing end if %> </BODY> </HTML> |
|
#7
|
|||
|
|||
|
if the user has multiple radio button groups for example
question2 and question3 also - how could the onSubmit handle this ? Quote:
|
|
#8
|
||||
|
||||
|
You would just have to modify the script to remove the btnName argument and hard code the questions.
|
![]() |
| Viewing: ASP Free Forums > Other > Development Articles > Validating Radio Button Groups with JavaScript |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|