funbinod Posted March 21, 2014 Share Posted March 21, 2014 i tried this - to disable form field if CHECKED and if UNCHECKED cancel disable. but it didnt work on my browser "chrome 33.0.1726.0" and "IE 11". please help me find out the error..... please help me find out the error ------ <form action="#"><h3><u>Shipping Address:</u></h3>Address:<input type="text" name="shipAdd" id="shipAdd"><br /><br />City:<input type="text" name="shipCity" id="shipCity"><br /><hr align="left" width="15%" noshade color="#996666" />Billing address same as shipping address.<input type="checkbox" name="billAdd" id="billAdd"><br /><br />Address:<input type="text" name="add" id="add" class="baddr"><br /><br />City:<input type="text" name="city" id="city" class="baddr"><br /><br /><input type="submit" name="submit" id="submit" value="SUBMIT"></form><script type="text/javascript"> $(document).ready(function(e) { $("#billAdd").click(function() { if ($("#billAdd").attr("checked") == "checked") { $(".baddr").val(""); $(".baddr").attr("disabled","disabled"); } else if ($("#billAdd").attr("checked") == "undefined") { $(".baddr").removeAttr("disabled"); } }); });</script> Link to comment Share on other sites More sharing options...
thescientist Posted March 21, 2014 Share Posted March 21, 2014 First, I wouldn't make it based on a click event of the billAdd input. Make it on the change event of the checkbox itself http://stackoverflow.com/questions/3642993/jquery-on-checked-toggle-box then, inside that event handler, I would use is(':checked'); for testing the checkbox state http://stackoverflow.com/questions/8391084/how-to-check-if-check-box-is-checked-in-this-example-javascript-jquery and use true / false when setting the disabled state http://stackoverflow.com/questions/1414365/how-to-disable-enable-an-input-with-jquery Link to comment Share on other sites More sharing options...
Petrucho Posted March 21, 2014 Share Posted March 21, 2014 You don't CLICK Checkbox's, you CHECK them. Look here for more information regarding the :checked selector. Link to comment Share on other sites More sharing options...
funbinod Posted March 22, 2014 Author Share Posted March 22, 2014 wow! thank u both of u for the guidance. i made it work now. now i again stuck on retriving data for "Billing Address" from "Shipping Address" field for 'IF CHECKED' clause. i tried this $("#add").val($("#shipAdd")); but it didn't work. please guide... Link to comment Share on other sites More sharing options...
funbinod Posted March 22, 2014 Author Share Posted March 22, 2014 wow! and i got it! i just edited this to - $("#add").val($("#shipAdd").val()); and it worked.... 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now