Development Articles
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherDevelopment Articles

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rating: Thread Rating: 3 votes, 4.00 average. Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old April 9th, 2004, 04:05 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,770 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 7 h 4 m 46 sec
Reputation Power: 469
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>

Reply With Quote
  #2  
Old May 12th, 2004, 09:17 AM
markoc's Avatar
markoc markoc is offline
Contributing User
ASP Free Regular (2000 - 2499 posts)
 
Join Date: Nov 2003
Location: UK
Posts: 2,151 markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 18 h 10 m 15 sec
Reputation Power: 201
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.....

Reply With Quote
  #3  
Old May 12th, 2004, 09:21 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,770 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 7 h 4 m 46 sec
Reputation Power: 469
try this
Code:
<Form onSubmit="Validate(this.form, 'question1')"> 

Reply With Quote
  #4  
Old May 12th, 2004, 09:31 AM
markoc's Avatar
markoc markoc is offline
Contributing User
ASP Free Regular (2000 - 2499 posts)
 
Join Date: Nov 2003
Location: UK
Posts: 2,151 markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 18 h 10 m 15 sec
Reputation Power: 201
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.

Reply With Quote
  #5  
Old May 12th, 2004, 09:56 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,770 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 7 h 4 m 46 sec
Reputation Power: 469
post your code.
btn is just the name of the radio group.

Reply With Quote
  #6  
Old May 12th, 2004, 10:02 AM
markoc's Avatar
markoc markoc is offline
Contributing User
ASP Free Regular (2000 - 2499 posts)
 
Join Date: Nov 2003
Location: UK
Posts: 2,151 markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level)markoc User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 18 h 10 m 15 sec
Reputation Power: 201
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>&nbsp;</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">&nbsp;Good Afternoon,
<%else%>
<font color="purple" size="5">&nbsp;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>&nbsp;</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): &nbsp;&nbsp;&nbsp;&nbsp;</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>

Reply With Quote
  #7  
Old February 24th, 2005, 10:32 AM
surfer163 surfer163 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 1 surfer163 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 11 sec
Reputation Power: 0
if the user has multiple radio button groups for example

question2 and question3 also - how could the onSubmit handle this ?



Quote:
Originally Posted by Memnoch
try this
Code:
<Form onSubmit="Validate(this.form, 'question1')"> 

Reply With Quote
  #8  
Old February 24th, 2005, 11:06 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,770 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 7 h 4 m 46 sec
Reputation Power: 469
You would just have to modify the script to remove the btnName argument and hard code the questions.

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherDevelopment Articles > Validating Radio Button Groups with JavaScript


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT