Quantcast
Channel: Adobe Community: Message List - ColdFusion
Viewing all articles
Browse latest Browse all 21760

dynamic check boxes validation

$
0
0

Hi all,

 

I have the query is displayed the check boxes.  I'd to validate and make sure at least one check box needs to be checked.  The code i have below is not working.  Can you please help.

 

Thanks

 

KT

 

<cfinclude template="userCheck.cfm">

script type="text/javascript">

        function validate(oForm) {

                var numChecked = 0;

                for (var idx=0; idx<oForm.category.length; idx++) {

                        if (oForm.category[idx].checked == true) {

                                numChecked++;

                                break;

                        }

                }

                if (numChecked > 0) {

                        return true;

                } else {

                        alert('Please check at least one checkbox');

                        return false;

                }

        }

</script>

 

<html>

<body>

<form onsubmit="return validate(this);"" action="next.cfm" id="form" name="form">

<cfoutput query="variables.category">

<input type="checkbox" name="category" id="category">#cat_var#

</cfoutput>

<input type="submit" value="Submit" />

</form>

</body>

</html>


Viewing all articles
Browse latest Browse all 21760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>