SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jul 2004
    Location
    dallas
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Problem with Syntax.

    <script language=text/javascript>
    function stf_chk(selObj)
    {


    if(document.getElementById('st_d' + selObj).getElementById('ST_DATE' + selObj).value == '')
    {

    document.getElementById('cp_d' + selObj).getElementById('CP_DATE' + selObj).disabled = true;
    }
    else
    {
    document.getElementById('cp_d' + selObj).getElementById('CP_DATE' + selObj).disabled = false;
    }
    }
    </script>


    <form name="st_d5" method="post" action="">
    <input type="text" id="ST_DATE5" onChange="std_add(5);" value="4/5/2002">
    <input name="st_dbound_cid5" type="hidden" value="5">
    </form>
    </td>
    <td>

    <form name="cp_d5" method="post" action="">
    <input type="text" id="CP_DATE5" onClick="stf_chk(5)" onChange="cpd_add(5)" value="">
    <input name="cp_dbound_cid5" type="hidden" value="5">
    </form>

    <input type="text" id="CP_DATE5" onClick="stf_chk(5)" onChange="cpd_add(5)" value="">


    I get an error on the OnClick="stf_chk(5)" I want to use onMouseover, but I get the same error . any ideas?

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    .getElementById() is a method of document - and nothing else. That's because it doesn't have to be: it gets an element, document-wide, by its id, regardless of where it sits in the document tree. You're calling it twice, to get the Form node and then as a method of that node (which it isn't). Once - for the Select - is plenty.

    You might be thinking of .getElementsByTagName(), which is a method of all element nodes, and will return a collection of descendents of that particular node.

    http://www.brainjar.com/dhtml/intro/
    ::: certified wild guess :::

  3. #3
    SitePoint Member
    Join Date
    Jul 2004
    Location
    dallas
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by adios
    .getElementById() is a method of document - and nothing else. That's because it doesn't have to be: it gets an element, document-wide, by its id, regardless of where it sits in the document tree. You're calling it twice, to get the Form node and then as a method of that node (which it isn't). Once - for the Select - is plenty.

    You might be thinking of .getElementsByTagName(), which is a method of all element nodes, and will return a collection of descendents of that particular node.

    http://www.brainjar.com/dhtml/intro/

    I am a Noobie at this Javascript, Was wondering what I did wrong, how would I fix it.

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What did you want to happen, exactly?
    ::: certified wild guess :::

  5. #5
    SitePoint Member
    Join Date
    Jul 2004
    Location
    dallas
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by adios
    What did you want to happen, exactly?

    If Textfeild is empty , then disable 2nd textfield, except the two fields reside in two diffrent forms and are dinamicly drawn IE
    Column 1
    FormA1
    TextboxA1
    FormA2
    TextBoxA2
    FormA3
    TextBoxA3

    Column 2

    FormB1
    TextboxB1
    FormB2
    TextBoxB2
    FormB3
    TextBoxB3

    Find TextBoxA3 if Empty then Disable TextBoxB3 Else Enable TextBoxB3

  6. #6
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure I follow the sequence of events - but to access the fields, all you need is document.getElementById(field_id). You don't need to reference the form object.
    Code:
    <script type="text/javascript">
    
    function stf_chk(n)
    {
        if (document.getElementById('ST_DATE' + n).value == '')
            document.getElementById('CP_DATE' + n).disabled = true;
        else document.getElementById('CP_DATE' + n).disabled = false;
    }
    
    </script>
    ::: certified wild guess :::

  7. #7
    SitePoint Member
    Join Date
    Jul 2004
    Location
    dallas
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Thanks that makes sence now,


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •