...

View Full Version : need help with a parentNode problem



bsharif
07-05-2006, 03:40 PM
<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
:thumbsup: :thumbsup: :thumbsup:

Beagle
07-05-2006, 04:14 PM
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.

bsharif
07-05-2006, 04:32 PM
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:o

bsharif
07-05-2006, 04:41 PM
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.

Beagle
07-05-2006, 05:09 PM
You're welcome BSharif, I'm sorry I was unable to resolve your problem in the earlier thread.

Mind the caps



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum