Jump to content

Enable and Disable Textbox.


casilda

Recommended Posts

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..

Link to comment
https://forums.phpfreaks.com/topic/193753-enable-and-disable-textbox/
Share on other sites

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);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.