html - Issue with JQuery onchange() event -
so have drop-down list , text-box:
<table> <tr> <td>group name: </td> <td><%= html.dropdownlistfor(m => m.indicationcalculatorgroupid, dropdowndata.indicationsgroup(sessionmanager.company.entityid, icconstants.indicationscalculatorgrouptype), "", new { propertyname = "indicationcalculatorgroupid", onchange = "updatefield(this, false);groupnamechange();" })%></td> </tr> <tr id="newgroupnamerow"> <td>new group name: </td> <td><%= html.textboxfor(m => m.indicationcalculatornewgroupname, new { @class = "economictextbox", propertyname = "indicationcalculatornewgroupname", onchange = "updatefield(this);" })%></td> </tr> </table>
i have jquery on page shows/hides text-box based on drop-down selection.
function groupnamechange() { $("#indicationcalculatorgroupid").change(function() { if ($("#indicationcalculatorgroupid option:selected").text() == 'create new group') { $("#newgroupnamerow").show(); } else{ $("#indicationcalculatornewgroupname").val(''); $("#newgroupnamerow").hide(); } }); }
but seems first time change drop-down "create new group", text-box doesn't show or anything, it's when select other value , select "create new group" code start work.
what's not wired correctly?
try put code when page loaded:
$(function() { $("#indicationcalculatorgroupid").change(function() { if ($("#indicationcalculatorgroupid option:selected").text() == 'create new group') { $("#newgroupnamerow").show(); } else{ $("#indicationcalculatornewgroupname").val(''); $("#newgroupnamerow").hide(); } }); });
Comments
Post a Comment