?
Solved

jQuery validation in Coldfusion page - question

Posted on 2011-10-04
2
Medium Priority
?
405 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:roger v
2 Comments
 
LVL 16

Assisted Solution

by:Gurpreet Singh Randhawa
Gurpreet Singh Randhawa earned 400 total points
ID: 36913274
use the this.id.replace(chkDel_,""), so u get the id of the checkbox and delete it
0
 
LVL 3

Accepted Solution

by:
devilJinKazama earned 1600 total points
ID: 36913673
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question