jquery - javascript validation when field hidden -
i have below code has dropdown. dropdown appears when other alternative selected. want validation checks when other alternative selected validate field not blank
this line works validation pops when box hidden looking check. have effort @ bottom there must improve nifty way works. thanks
if(!blank('otherprodtypebox[<xsl:value-of select="@id"/>]')){alert("please come in valid other option");return false;} <script type="text/javascript"> function myotherbox(e, id) { if (e.value == 'otherprodtype') { $('#mybox_' + id).show(); } else { $('#mybox_' + id).hide(); } } </script> <tr> <td class="label">product type</td> <td class="field"> <select name="producttypes"> <xsl:attribute name="onchange">myotherbox(this, '<xsl:value-of select="@id"/>'); checkboxvisible(this, '<xsl:value-of select="@id"/>')</xsl:attribute> <xsl:attribute name="id">producttypes_<xsl:value-of select="@id"/></xsl:attribute> <option value="a"> <xsl:if test="producttypes/option[@id='a']='selected'"> <xsl:attribute name="selected"/> </xsl:if>a</option> <option value="b"> <xsl:if test="producttypes/option[@id='b']='selected'"> <xsl:attribute name="selected"/> </xsl:if>b</option> <option value="otherprodtype"> <xsl:if test="producttypes/option[@id='otherprodtype']='selected'"> <xsl:attribute name="selected"/> </xsl:if>other</option> </select> </td> </tr> <tr style="display:none;"> <xsl:attribute name="id">mybox_<xsl:value-of select="@id"/></xsl:attribute> <td class="label">other</td> <td> <input class="amdinputtext" type="text" id="otherprodtypebox" value=""> <xsl:attribute name="value"><xsl:value-of select="otherprodtypebox"></xsl:value-of></xsl:attribute> </input> </td> </tr> if($('#mybox_' + id).validate({ ignore: ':hidden' });) { if(!blank('otherprodtypebox[<xsl:value-of select="@id"/>]')){alert("please come in valid other option");return false;} }
use class validation. is, validate class called, e.g., .validator.
in js:
function myotherbox(e, id) { if (e.value == 'otherprodtype') { $('#mybox_' + id).show().addclass('validator'); } else { $('#mybox_' + id).hide().removeclass('validator'); } }
edit: alternately, can utilize selector instead of above:
if($('#mybox_' + id + ':visible').....................etc
that'd better.
javascript jquery validation
No comments:
Post a Comment