javascript - Disabling a control based on checkbox state? -
i want disable referenced control in html , javascript below, yet it's not doing it. seems simple enough. missing?
<html xmlns="http://www.w3.org/1999/xhtml"> <head><title> </title> <script language="javascript" type="text/javascript"> function disable(isdisable, controlid) { var objcontrol = document.getelementbyid(controlid); if (objcontrol != null) { objcontrol.disabled = isdisable; } } </script> </head> <body> <form name="form1" id="form1"> <input name="date?4" type="text" value="1/1/2011 12:00:00 am" id="date?4" runat="server" style="border-color:black;font-family:arial;width:300px;" /><input type="checkbox" style="font-family: arial" onclick="disable(this.checked, "date?4" );" >disable </form></body> </html>
your onclick badly formatted:
onclick="disable(this.checked, "date?4" );"
use instead:
onclick="disable(this.checked, 'date?4' );"
if use double quotes ("
) attribute value delimiters, can't use them inside value without escaping them. should use single quotes ('
) inside.
Comments
Post a Comment