Javascript and asp.net - TextBox backcolor not changing...

Discussion in 'ASP .Net Web Controls' started by avanti, Oct 24, 2006.

  1. avanti

    avanti Guest

    i have a following javascript function that gets called on a checkbox
    click. The backcolor is not getting changed for the textbox. I am
    seeing an error on page as well. I am using IE and C# with the asp
    code.

    function enableExterNameTextBox(obj)
    {
    var textbox = "";
    textbox = document.getElementById('partnerExternalName');
    if(obj.checked)
    {
    alert('checked');
    textbox.disabled = true;
    textbox.value = "";
    textBox.style.backgroundColor = 'gray';
    }
    else
    {
    alert('unchecked');
    textbox.disabled = false;
    textBox.style.backgroundColor = 'white';
    }
    }


    Any ideas?
    Thanks,
    Avanti
     
    avanti, Oct 24, 2006
    #1
    1. Advertising

  2. avanti

    Scott M. Guest

    Well, the code below works for me, but since you didn't provide the full
    HTML code, I can't really say much more:

    <HTML>
    <HEAD>

    <SCRIPT>
    function enableExterNameTextBox(obj)
    {
    var tb = document.getElementById("partnerExternalName");
    var cb = obj;

    if(cb.checked)
    {
    alert("checked");
    tb.disabled = true;
    tb.value = "";
    tb.style.backgroundColor = "#E0E0E0";
    }
    else
    {
    alert("unchecked");
    tb.disabled = false;
    tb.style.backgroundColor = "#FFFFFF";
    }
    }

    </SCRIPT>
    </HEAD>
    <BODY>

    <FORM ID="frmTest">
    <INPUT TYPE="Checkbox" ID="chkColor" onClick="enableExterNameTextBox(this)">
    <INPUT TYPE="TEXT" ID="partnerExternalName" />

    </FORM>

    </BODY>
    </HTML>

    ----------------------------------------------------------------



    "avanti" <> wrote in message
    news:...
    >i have a following javascript function that gets called on a checkbox
    > click. The backcolor is not getting changed for the textbox. I am
    > seeing an error on page as well. I am using IE and C# with the asp
    > code.
    >
    > function enableExterNameTextBox(obj)
    > {
    > var textbox = "";
    > textbox = document.getElementById('partnerExternalName');
    > if(obj.checked)
    > {
    > alert('checked');
    > textbox.disabled = true;
    > textbox.value = "";
    > textBox.style.backgroundColor = 'gray';
    > }
    > else
    > {
    > alert('unchecked');
    > textbox.disabled = false;
    > textBox.style.backgroundColor = 'white';
    > }
    > }
    >
    >
    > Any ideas?
    > Thanks,
    > Avanti
    >
     
    Scott M., Oct 25, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Bond
    Replies:
    1
    Views:
    570
    Chris Bond
    Sep 17, 2003
  2. =?Utf-8?B?cm9kY2hhcg==?=

    stylesheet textbox backcolor

    =?Utf-8?B?cm9kY2hhcg==?=, Nov 9, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    827
    =?Utf-8?B?cm9kY2hhcg==?=
    Nov 9, 2006
  3. Chris Bond

    Changing row backcolor based on a column value from dataset

    Chris Bond, Sep 17, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    247
    Chris Bond
    Sep 17, 2003
  4. Mircea Pleteriu

    TextBox and BackColor

    Mircea Pleteriu, Jun 15, 2004, in forum: ASP .Net Mobile
    Replies:
    0
    Views:
    138
    Mircea Pleteriu
    Jun 15, 2004
  5. Replies:
    1
    Views:
    926
    Alessandro Zifiglio
    Jul 20, 2006
Loading...

Share This Page