...

View Full Version : Help with script ?



daveflinders
04-18-2007, 06:52 PM
Hi, i hope i'm in the right forum. Need some help, i'm getting a null error with the document.all.divID part of this script.



<script language="javascript">

var htmlArray = new Array();

htmlArray['1'] = '<div id="display"><a href="#" onClick="expand_div(2)";><< Cancel this addition</a><br><br><table style="border: 4px dashed red;" cellpadding="2" ><tr><td width="300" align="center" colspan="3" bgcolor="#FFFFCC">Model: <input type="text" size="38"></td><td width="200" align="center" colspan="2" bgcolor="#FFFFCC">Year: <input type="text" size="20"></td><td size="100" align="center" bgcolor="#FFFFCC">CC: <input type="text" size="5"></td></tr><tr><td width="300" align="center" colspan="3" bgcolor="#FFFFCC">Type: <input type="text" size="38"></td><td width="300" align="center" colspan="4" bgcolor="#FFFFCC">Details: <input type="text" size="35"></td></tr><tr><td width="594" align="left" colspan="6" bgcolor="#FFFF66">&nbsp;</td></tr><tr><td align="center" bgcolor="#FFFF66">Denso</td><td align="center" bgcolor="#FFFF66">Denso Iridium</td><td align="center" bgcolor="#FFFF66">NGK</td><td align="center" bgcolor="#FFFF66">NGK IX</td><td align="center" bgcolor="#FFFF66">Champion</td><td align="center" bgcolor="#FFFF66">Bosch</td></tr><tr><td align="center" bgcolor="#FFFF66"><input type="text" size="12"></td><td align="center" bgcolor="#FFFF66"><input type="text" size="12"></td><td align="center" bgcolor="#FFFF66"><input type="text" size="12"></td><td align="center" bgcolor="#FFFF66"><input type="text" size="12"></td><td align="center" bgcolor="#FFFF66"><input type="text" size="12"></td><td align="center" bgcolor="#FFFF66"><input type="text" size="12"></td></tr><tr><td colspan="6"><input type="button" value="Add to Catalogue"></td></tr></table></div>';

htmlArray['2'] = '<div id="repeat"><a href="#" onClick="expand_div(1)";>Add to catalogue at this point >></a></div>';


function expand_div(chosID,locID) {

var divID;

divID = "add_to_catalogue" + locID;



if(document.all) {
document.all.divID.innerHTML = htmlArray[chosID];
}
else {
document.getElementById('divID').innerHTML = htmlArray[chosID];
}
return false;
}

</script>

<body>

<div id="add_to_catalogue1">
<a href="#" onClick="expand_div(1,1)";>Add to catalogue at this point >></a>
</div>

<div id="add_to_catalogue2">
<a href="#" onClick="expand_div(1,2)";>Add to catalogue at this point >></a>
</div>

Thanks in advance.

nikkiH
04-18-2007, 07:03 PM
document.all is for old MSIE.
Use document.getElementById first, then check for document.all.

That said, if you're using a variable like that, you need
document.all[divId]

The dot syntax the way you have it is a shortcut for the real ID, not a variable storing the ID.

daveflinders
04-19-2007, 11:10 AM
Thanks for your help .. :thumbsup:

I've changed the order to this ..

divID = "add_to_catalogue" + locID;

if(document.getElementById) {
document.getElementById('divID').innerHTML = htmlArray[chosID];
}

else {

document.all[divID].innerHTML = htmlArray[chosID];

}

But i'm still getting errors with the getElementById argument. The problem is with the ('divID') part .. what would be the correct syntax ?

Thanks

nikkiH
04-19-2007, 05:18 PM
Remove the single quotes if that's a variable.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum