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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with script ?

    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.

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New to the CF scene
    Join Date
    Apr 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your help ..

    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

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Remove the single quotes if that's a variable.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

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