jQuery validation in Coldfusion page - question

Hi,

I have a coldfusion 9 page where I'm using jquery for validating user input. I'm having trouble coming up with the exact syntax since I've got checkbox elements that are being dynamically named using the CurrentRow value. My code is attached. TIA
<script src="../scripts/validateUser.js" language="javascript" type="text/javascript"></script>
<script language="javascript">
	$(document).ready(function(){
		$("#btn2").bind('click', checkDelete);
	});
</script>

<!---this is where my checkboxes are created--->
<cfoutput query="Users">
    <tr class="delegatesRows">
        <td>#userid#</td>
        <td>#lastname#</td>
        <td>#firstname#</td>
        <td>#type#</td>
		<td><input type="checkbox" name="chkDel_#currentrow#" id="chkDel_#currentrow#" value="#userid#" class="chkDel" /></td>
    </tr>
</cfoutput>
<!---end user.cfm page--->

<!---validateUser.js file that is loaded at the top after the jquery lib in my user.cfm page--->

<!---this is where I need help to figure out if the user has checked any rows or not. If the user has not checked anything, then they get an alert stating they need to check atleast one checkbox. If they check one or more, then they get a confirmation box asking if they want to proceed--->
var checkDelete = function(){
	alert($(".chkDel").attr("id"));
	if($(".chkDel")==undefined){
		alert("Atleast one entry has to be checked to be deleted!");
		return false;
	}
	if(confirm("Are you sure you want to delete the checked user/s?")){
		return true;
	}
	else{
		alert("Delete cancelled!");
		return false;
	}
}
<!---the above code as it stands does not work--->

Open in new window

LVL 1
roger vAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gurpreet Singh RandhawaWeb DeveloperCommented:
use the this.id.replace(chkDel_,""), so u get the id of the checkbox and delete it
0
devilJinKazamaCommented:
this should work for u,

<script src="../scripts/validateUser.js" language="javascript" type="text/javascript"></script>
<script language="javascript">
      $(document).ready(function(){
            $("#btn2").bind('click', checkDelete);
      });
</script>

<!---this is where my checkboxes are created--->
<cfoutput query="Users">
    <tr class="delegatesRows">
        <td>#userid#</td>
        <td>#lastname#</td>
        <td>#firstname#</td>
        <td>#type#</td>
            <td><input type="checkbox" name="chkDel_#currentrow#" id="chkDel_#currentrow#" value="#userid#" class="chkDel" /></td>
    </tr>
</cfoutput>
<!---end user.cfm page--->

<!---validateUser.js file that is loaded at the top after the jquery lib in my user.cfm page--->

<!---this is where I need help to figure out if the user has checked any rows or not. If the user has not checked anything, then they get an alert stating they need to check atleast one checkbox. If they check one or more, then they get a confirmation box asking if they want to proceed--->
var checkDelete = function(){
      if($('.chkDel:checked').size() == 0){
            alert("Atleast one entry has to be checked to be deleted!");
            return false;
      }
      if(confirm("Are you sure you want to delete the checked user/s?")){
            return true;
      }
      else{
            alert("Delete cancelled!");
            return false;
      }
}
<!---the above code as it stands does not work--->

all i changed was this line :

from : if($(".chkDel")==undefined){

to : if($('.chkDel:checked').size() == 0){
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.