javascript - Trouble shooting jquery enable/disable text box based on radiobutton again -


after getting piece right, (trouble shooting jquery enable/disable text box based on radiobutton) found neede add field form, disabled if radio selection made.

seems have broken whole thing , cannot find problem is.

i've rewritten code try , make sense of (i don't know javascript @ all)

<input type="radio" name="radioknof" value="public" checked/> <label "public">anyone</label> </br> <input type="radio" name="radioknof" value="direct" /> <label for="direct">specific</label> </br> <label for="newmanagerfirstname">manager's firstname :</label> <input type="text" name="newmanagerfirstname" id='newmanagerfirstname' value="1"> </br> <label for="newmanageremail">manager's email address:</label> <input type="text" name="newmanageremail" id='newmanageremail' value="2"> 

and then

$(window).load(setdefault()); $('input[name=radioknof]').on('click', unorlock());  function setdefault() {     $("#newmanageremail").prop("disabled", true);     $("#newmanagerfirstname").prop("disabled", true); }  function unorlock() {     if (this.checked && this.value == "public") {         $("#newmanageremail").prop("disabled", true);         $("#newmanagerfirstname").prop("disabled", true);     } else {         $("#newmanageremail").prop("disabled", false);         $("#newmanagerfirstname").prop("disabled", false);     } } 

please tell i'm missing ...?

like banana said, there's adjustement do, put ids radio buttons, validate code every time, don't see problem http://validator.w3.org/, don't think w3school best place start www.w3fools.com, mozilla mdn seams better https://developer.mozilla.org/docs/web/javascript have many ebooks online.

nikhil's solution can reduce little bit :

$(document).ready(function(){ $('[name=radioknof]').click(function(){ if (this.checked && this.value == "public") { $("#newmanageremail, #newmanagerfirstname").prop("disabled", true); } else { $("#newmanageremail, #newmanagerfirstname").prop("disabled", false); } }); });


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -