javascript - how can put a variable ID into asp.net code inside java script? -
i'm trying turn textbox enable , disable depends on checked checkbox java script, there anyway this?
here code
<script type="text/javascript"> function ed1(benable, textboxid, textboxid2) { document.getelementbyid("<%= textboxid.clientid %>").disabled = !benable document.getelementbyid("<%= textboxid2.clientid %>").disabled = !benable } </script>
here checkbox , text box
<asp:checkbox id="ch0" runat="server" font-names="tahoma" onclick="ed1(this.checked, 'tb1', 'tb2');" font-size="x-small" style="font-size: 12px; right: 20px; color: #006699; font-family: tahoma; position: absolute; top: 25px; width: 80px;" /> <asp:textbox id="tb0" runat="server" enableviewstate="false" height="12px" maxlength="2" style="font-size: 11px; right: 110px; vertical-align: middle; color: #0099ff; font-family: tahoma; position: absolute; top: 25px; text-align: left; width: 15px; " enabled="false" wrap="false" validationgroup="1234567890"></asp:textbox> <asp:textbox id="tb1" runat="server" enableviewstate="false" height="12px" maxlength="2" style="font-size: 11px; right: 140px; vertical-align: middle; color: #0099ff; font-family: tahoma; position: absolute; top: 25px; text-align: left; width: 15px; " enabled="false" wrap="false" validationgroup="1234567890"></asp:textbox>
it won't work asp doesn't undrestand textboxid means! (it has been declared on javascript!)
i'm getting following error:
bc30451: 'textboxid' not declared. may inaccessible due protection level.
if put actual ids instead of textboxid2 works great have many check box , many text box enable , disable making countless javascript doesn't seems idea!
let me know if can solvable , in advance
found solution accident, can't put asp code qoute can put javascript string code asp code :d :d should =>
onclick='<%# "ed1(this.checked, " & tb1.clientid & ", " & tb2.clientid & ");" %>'
also java script code must =>
<script type="text/javascript"> function ed1(benable, textboxid, textboxid2) { document.getelementbyid(textboxid).disabled = !benable; document.getelementbyid(textboxid2).disabled = !benable; } </script>
hope helps in future :-)
Comments
Post a Comment