Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2006
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    need help with a parentNode problem

    Code:
    <head>
      <title></title>
    <style type="text/css">
    
    .FrmDiv {
      position:absolute;visibility:hidden;width:200px;
    }
    
    
    </style>
    
    <script language="JavaScript" type="text/javascript">
    
    
    var SelAry=[];
    
    SelAry[0]=['Select IP','Selectid'];
    SelAry[1]=['Name IP','nameip'];
    SelAry[2]=['Phone IP','phone'];
    
    function Populate(id,ary,fun){
     var sel=document.getElementById(id)
     for (var zxc0=0;zxc0<ary.length;zxc0++){
      sel.options[zxc0]=new Option(ary[zxc0][0],ary[zxc0][1],true,true);
     }
     sel.selectedIndex=0;
     sel.onchange=function(){ window[fun](this); }
    }
    
    function CngIP(obj){
     var ipobj;
     if (obj.ipobj){
      obj.ipobj.style.visibility='hidden';
     }
     if (obj.value){
      ipobj=obj.form[obj.value].parentNode;
      ipobj.style.visibility='visible';
    
    
    
    
     }
     obj.ipobj=ipobj;
    }
    
    
    </script>
    
    </head>
    
    <body onload="Populate('IPSel',SelAry,'CngIP')">
    <br /><br />
    
    <center><form>
    <select id="IPSel" name=IPSel" ></select>
    <div class="FrmDiv">
    Name <input type=text name="nameip"  />
    </div>
    
    </form>
    </center></body>
    </html>
    Hello to all, I need some help the above code works fine compiles and runs but when i use it with the browser,
    the browser gives an error message saying that parentNode is null or not an object . Need to determine whats taken place to fix problem.
    code works fine all you need to do is copy/paste code to notepad to see the error message that it gives at the left bottom corner of the web
    browser.

    the code basically opens up a textfield when a certain topic is chosen from the droplist

    Thank you for all your help

  • #2
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    Didn't you post this somewhere else and I responded? Or is this an incredibly similar question from a different person.

    Regardless, ths problem is you're trying to access the parentNode of something that doesn't have a parentNode property, meaning it isn't an HTMLElement like you think it is.

    That would be because you're attempting to access a form field with a name that is stored in the value of another form field. If that form field's value is not equivalent to the name of another field in the form, then you'll get a null pointer.

    Put an alert of obj.value before this line:
    pobj=obj.form[obj.value].parentNode;

    and try to figure out what value of obj.value is causing it to fail.

    If you need a workaround, you can do:

    if (obj.form[obj.value])
    pobj = obj.form[obj.value].parentNode;

    That would only let you play with the field if it in fact existed. But that might break other things based on what your expectations are. Basically, your select field is populated with a bunch of values and they need to correspond to the names of form fields, which it doesn't seem like they do currently.

  • #3
    New Coder
    Join Date
    Jun 2006
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    YEAH YOU ARE RIGHT , I POSTED THIS EARLIER LAST WEEK BUT I AM STILL GETTING ERRORS, THE DROPLIST GETS FILLED BY THE ARRAY BUT FOR SOME REASON IT POINTS TO NULL WHEN USER CHOSES SOMETHING OTHER THAN FTP , WHICH OPENS UP THE TEXTFIELD.PLEASE OPEN IN NOTE PAD AND CHECK OUT

    THANKS

  • #4
    New Coder
    Join Date
    Jun 2006
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I FIXED IT I JUST DELETE THE ARRAYS THAT I WAS NOT USING:

    EXAMPLE

    SelAry[0]=['Select IP','SELECT IP'];
    SelAry[1]=['Name IP','nameip'];
    SelAry[2]=['Phone IP','phoneip'];

    GOT CHANGED TO

    SelAry[0]=['Select IP'];
    SelAry[1]=['Name IP','nameip'];
    SelAry[2]=['Phone IP'];

    simply mistake

    thank you for your help Beagle you help me think when i hit a brick wall.

  • #5
    Senior Coder
    Join Date
    Jul 2005
    Location
    New York, NY
    Posts
    1,084
    Thanks
    4
    Thanked 19 Times in 19 Posts
    You're welcome BSharif, I'm sorry I was unable to resolve your problem in the earlier thread.

    Mind the caps


  •  

    Posting Permissions

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