Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validating CheckBoxes within an ASP page 1

Status
Not open for further replies.

rizza

Programmer
Jul 16, 2002
66
US
I have a table of "news clips", generated from a db. There is checkbox next to each one, that's used to mark it for deletetion.

<% REsponse.write(&quot;<input type=&quot;&quot;checkbox&quot;&quot; name=&quot;&quot;RecordId&quot;&quot; value=&quot;&quot;&quot; & rs.fields(&quot;RecordId&quot;) &&quot;&quot;&quot; ></td>&quot;) %>


form name = frmDeleteEvent

I need to loop through these onClick of the submit button and make sure one is checked. I'm having a tough time getting any code to work and my head is so shot from staring at this morning. Ne help would be great.

The checkboxes are the only items on the form. And the number of checkboxes grows and shrinks depending on the DB.

Thanks,
Rizza
 
You could loop through the collection of form checkboxes similar to how I did it a few posts ago for disabling all the inputs in a form:
Code:
function disableAll(){
	for(var i = 0;i < document.getElementsByName(&quot;RecordId&quot;).length;i++){ 
		if(document.getElementsByName(&quot;RecordId&quot;)[i].checked == true){
			//at least one is checked
			return true;	
		}
	}
	//Nothing checked
	alert(&quot;You have not selected anything for deletion!&quot;);
	return false;
}


A little bulky, and there are probably better ways to do it, but that should work. Warning I did write this on the fly, so beware errors.

-Tarwn
This code is rather bulky, it would be better if you --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
With enough resources, time, and coffee, anything is possible.
 
Ok great it works at making sure there is something checked.

But when i added the document.frmDeleteEvent.submit it didnt submit. What am i missing, i'm sure it's with the return statements.....but how or what i'm lost...

<input type=&quot;button&quot; name=&quot;bSubmit&quot; value=&quot;Delete&quot; onClick=&quot;CheckForm()&quot;>

<script language=&quot;JavaScript&quot;>
function CheckForm(){
for(var i = 0;i < document.getElementsByName(&quot;RecordId&quot;).length;i++){
if(document.getElementsByName(&quot;RecordId&quot;).checked == true){
//at least one is checked
document.frmDeleteEvent.submit; return true;
}
}
//Nothing checked
alert(&quot;You have not selected anything for deletion!&quot;);
return false;
}

</script>

Thanks man
 
I got it now...

<form name=&quot;frmDeleteEvent&quot; method=&quot;post&quot; action=&quot;DiscountPrgm_CMS.asp?form=deleted&quot; onSubmit=&quot;return CheckForm(this)&quot;>


function CheckForm(form){
for(var i = 0;i < document.getElementsByName(&quot;RecordId&quot;).length;i++){
if(document.getElementsByName(&quot;RecordId&quot;).checked == true){
//at least one is checked
return true;
}
}
//Nothing checked
alert(&quot;You have not selected anything for deletion!&quot;);
return false;
}

Now it's all starting to come back to me.
 
Or you could do with it ASP, then you wouldn't have to do a loop..

check.asp:

<%
If Request.QueryString(&quot;error&quot;) <> &quot;empty&quot; then
Response.Write &quot;you did not check any checkboxes..

'#--checkboxes next..->
%>


delete.asp:
Code:
If Request.Form(&quot;RecordId&quot;) <> &quot;&quot; then
'# db conn
'# create obj
  
 strSQL = &quot;Delete from table_name where ID in (&quot; & Request.Form(&quot;RecordId&quot;) & &quot;)&quot;

'# exe db conn

  Else
Response.Redirect &quot;check.asp?error=empty
End If
www.vzio.com
ASP WEB DEVELOPMENT



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top