hiding-enabling text fields

Discussion in 'Javascript' started by Malinmore, Jul 27, 2008.

  1. Malinmore

    Malinmore Guest

    the following works well regarding one select box with one hidden text
    box. however I need two unique select boxes with relevant hidden text
    boxes that un-hide when the Add New option is selected. the problem is
    that the upper hidden text box always appears when the page is loaded.
    Can anyone tells me why?

    //physicianID

    function enableOtherPhysicians()
    {
    if (!document.getElementById) return;

    var s1 = document.getElementById('referpersonID');
    if (!s1) return;
    if (s1.options[s1.selectedIndex].value != 'referpersonID') return;
    var t1 = document.getElementById('referpersonIDnew');
    var d1 = document.getElementById('delete1');
    if (!t1) return;
    t1.disabled = false;
    t1.className = '';
    d1.disabled = true;
    d1.className = '';

    var s3 = document.getElementById('physicianID');
    if (!s3) return;
    if (s3.options[s3.selectedIndex].value != 'physicianID') return;
    var t3 = document.getElementById('physicianIDnew');
    var d3 = document.getElementById('delete3');
    if (!t3) return;
    t3.disabled = false;
    t3.className = '';
    d3.disabled = true;
    d3.classname = '';
    }

    function initPhysicians()
    {
    if (!document.getElementById) return;

    var s1 = document.getElementById('referpersonID');
    if (!s1) return;
    s1.onchange = enableOtherPhysicians;
    var t1 = document.getElementById('referpersonIDnew');
    var d1 = document.getElementById('delete1');
    if (!t1) return;
    t1.disabled = true;
    t1.className = 'person_hidden';
    d1.disabled = false;
    d1.className = 'person_hidden';

    var s3 = document.getElementById('physicianID');
    if (!s3) return;
    s3.onchange = enableOtherPhysicians;
    var t3 = document.getElementById('physicianIDnew');
    var d3 = document.getElementById('delete3');
    if (!t3) return;
    t3.disabled = true;
    t3.className = 'physician_hidden';
    d3.disabled = false;
    d3.classname = 'physician_hidden';
    }

    window.onload = initPhysicians;
     
    Malinmore, Jul 27, 2008
    #1
    1. Advertising

  2. On Jul 27, 1:36 pm, Malinmore <> wrote:
    > the following works well regarding one select box with one hidden text
    > box. however I need two unique select boxes with relevant hidden text
    > boxes that un-hide when the Add New option is selected. the problem is
    > that the upper hidden text box always appears when the page is loaded.
    > Can anyone tells me why?


    No because your description relates to the position of the elements
    while the code operates on their IDs. Your code is badly written and
    you don't appear to have made any effort at diagnosing the fault
    yourself.

    You might want to
    1) see if you are getting any javascript errors at runtime
    2) try somethnig along the lines of:

    function initPhysicians()
    {
    alert("initPhysicians() started");
    if (!document.getElementById) {
    alert("No document.getElementByID method");
    return false;
    }

    var s1 = document.getElementById('referpersonID');
    if (s1) {
    s1.onchange = enableOtherPhysicians;
    } else {
    alert("referpersonID not found");
    return false;
    }
    var t1 = document.getElementById('referpersonIDnew');
    if (t1) {
    t1.disabled = true;
    t1.className = 'person_hidden';
    } else {
    alert("referpersonIDnew not found");
    return false;
    }
    var d1 = document.getElementById('delete1');
    ....

    C.
     
    C. (http://symcbean.blogspot.com/), Jul 27, 2008
    #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. call_me_anything
    Replies:
    4
    Views:
    469
    Pete Becker
    Sep 30, 2007
  2. Old Lady
    Replies:
    4
    Views:
    134
    Old Lady
    Feb 14, 2005
  3. Replies:
    2
    Views:
    110
    Mister Joe
    Feb 6, 2007
  4. Ste
    Replies:
    41
    Views:
    812
    Thomas 'PointedEars' Lahn
    Aug 1, 2007
  5. jpw

    enabling all fields on a form

    jpw, Aug 5, 2007, in forum: Javascript
    Replies:
    2
    Views:
    101
Loading...

Share This Page