Skip to main content
Participating Frequently
May 27, 2009
Question

ColdFusion and Javascript not working

  • May 27, 2009
  • 1 reply
  • 860 views

I have the form where I have a pair of checkboxes. 1 to insert another to verify. For example, if there are three line items, there are three checkboxes for the insert and then three checkboxes for the verify. My task is I can only submit the form if both checkboxes are checked otherwise through the error message. I have a little code. But does not seems to be working. What am I doing wrong?

<cfset lcount = #getCareManagers.recordcount#>

<script language="javascript">

function validate(){ var i; var valueDel; var valueEdit;       for (i = 1; i < <cfoutput>#lcount#</cfoutput>; i++)      {      var valueDel = document.getElementById('ins_'+i).checked;      var valueEdit = document.getElementById('verify_'+i).checked;           //alert (valueDel);                       if(valueDel==true && valueEdit==true)           {                     alert(valueDel);                document.forms.frmCheck.submit();                           }      } alert('error, cannot be both checked');                return false; } </script>

<form name="frmCheck" action="checkCompletion.cfm" method="post">

<input type="checkbox" name="ins_#currentrow#" id="ins_#currentrow#"  <cfif isDate(checkCompletion.completiondate)>disabled="disabled" class="green" checked</cfif>/>

<input type="checkbox" name="verify_#currentrow#" id="verify_#currentrow#" <cfif isDate(checkCompletion.completiondate)>disabled="disabled" class="green" checked</cfif>/>

<input type="submit" name="btnSubmit" id="btnSubmit" value="Complete The Course" onclick="validate ();"/>

</form>

    This topic has been closed for replies.

    1 reply

    Inspiring
    May 27, 2009

    Troubleshooting javascript is tedious, but the general priniciple is the same as troubleshooting anything else.  When in doubt, look at the data.

    I suggest that you start moving your function call from the onclick event of the submit button to the onsubmit event of the form.  Next, comment out your entire function and add an alert to output some simple text.  This will tell you whether the function got called.

    Then start uncommenting text and outputting your data using window.alert until it fails.  Then you'll know where your mistakes are.