casilda Posted March 1, 2010 Share Posted March 1, 2010 I have a php form page, in which some of the fields are called from the database and some of the fields are blank. I have one field as country in which i call the data from the database: and another field as Telephone : it has 3 fields with all that code stuffs: what i want is eg: For US: i have 3 fields for telephone numbers to enter in.. If the country is India : I need one of the field to be disabled.. so, wat i did is I passed the value of the pulled in data into a textbox and check conditions.. My code is below: function disable() { var db = document.form1.txt_c.value; // gets the value from the database var hid = document.form1.spore.value; //It is a predifined value to check and its hidden,.. if(db = hid) { document.form1.t2.disabled=true; } else { document.form1.t2.disabled=false; } } Then i called the functiion as below, <input name="address" type="text" id="address" size="50" onblur="disable()"/> It doesnt work for me...my else part doesnt work for me.. Quote Link to comment https://forums.phpfreaks.com/topic/193753-enable-and-disable-textbox/ Share on other sites More sharing options...
Psycho Posted March 1, 2010 Share Posted March 1, 2010 Your IF condition is doing an assignment (which is always returning true) not a comparison. Change it to double equal signs to do a comparison. Although, you are making the code more complext than it needs to be. Just do this: function disable() { var formObj = document.forms['form1'].elements; formObj['t2'].disabled = (formObj['txt_c'].value==formObj['spore'].value); } Quote Link to comment https://forums.phpfreaks.com/topic/193753-enable-and-disable-textbox/#findComment-1020108 Share on other sites More sharing options...
casilda Posted March 2, 2010 Author Share Posted March 2, 2010 Hey thanks for ur reply.. I did it in another way and it worked.. anyway thanks a lot... Quote Link to comment https://forums.phpfreaks.com/topic/193753-enable-and-disable-textbox/#findComment-1020290 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.