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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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