Coldfusion cfform validation for hidden fields -


i have form select box options. if user selects other option, display hidden text field in user has enter choice. both form fields required fields. validation fails when select other options other 'other'. can 1 me?

the code given below:

<script >  function opnselect() {       var opval = document.test_form.opns.value;       if (opval == "other") {           // document.getelementbyid('td_options').style.display='none';           document.getelementbyid('td_opns1').style.display="";       }       else if(opval!="other"){          document.getelementbyid('td_opns1').style.display='none';       }   } </script> <cfform name="test_form"> <table>  <tr>   <td width="120" align="right"><font color="#ff0000"><b>please select options</b></font></td>      <td align="left" id="td_options">         <cfselect size="1"  style="width:150px" name="opns" id="opns" required="true"   message="please select value" onchange="javascript:opnselect();">             <option value="" ></option>             <option value="value1">value1</option>             <option value="value2">value2</option>             <option value="value3">value3</option>             <option value="other">other</option>          </cfselect>     </td>  </tr>  <tr id="td_opns1" style="display:none;"  >    <td align="right"><b><font color="#ff0000"> choice</font></b></td>    <td align="left" >     <cfinput type="text" name="opns1" id="opns1"  required="true"  message="please enter choice" >  </td>  </tr>  </table> <cfinput type="submit" value="submit" name="submit1"> 

i think easiest solution may add default value opns1 satisfy required condition when besides "other" selected.

<cfinput type="text" name="opns1" id="opns1" value="other"  required="true"  message="please enter choice" > 

in js if (opval == "other") condition add

document.getelementbyid('opns1').value=""; // clear "other" input. 

in form handler, check make sure opns1 neq "other"

<cfif form.opns1 neq "other">   new value </cfif> 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -