message of 'is null or not an object'

Discussion in 'Javascript' started by CreativeMind, Jun 12, 2008.

  1. CreativeMind

    CreativeMind Guest

    hi all,

    my dropdownlist 'cboUnitTypes' is populating on the base of another
    dropdownlist1, i have to apply a check on 'cboUnitTypes' like
    if(cboUnitTypes[cboUnitTypes.selectedindex].value==0)return false; now
    problem is; i face an error describing 'cbounittypes is either null or
    not an object' when i see view source, firefox and IE showing
    different source code.firefox is showing right. but IE not. what's
    reason??



    ----- viewsource using firefox

    <select name="cboUnitTypes" onchange="javascript:return
    ConfirmDeleteImage();__doPostBack('cboUnitTypes','')"
    language="javascript" id="cboUnitTypes"
    class="TextFieldNormalForProperty">
    <option selected="selected" value="0"></option>
    <option value="396">34</option>
    <option value="405">nothing</option>
    <option value="412">test</option>

    </select>

    ----- viewsource using IE

    <select name="cboUnitTypes" onchange="javascript:return
    ConfirmDeleteImage();__doPostBack('cboUnitTypes','')"
    language="javascript" id="cboUnitTypes"
    class="TextFieldNormalForProperty" style="width:200px;">

    </select>
     
    CreativeMind, Jun 12, 2008
    #1
    1. Advertising

  2. CreativeMind

    CreativeMind Guest

    thx.
    error message is no more raising.
    > As for the error you're seeing. If you post the Javascript that's
    > generating this error, we'll have a better chance of helping you

    ----
    but i can't my dropdownlist values in IE.
    here is complete info.

    <select name="cboUnitTypes" onchange="javascript:return
    ConfirmDeleteImage();__doPostBack('cboUnitTypes','')"
    language="javascript" id="cboUnitTypes"
    class="TextFieldNormalForProperty" style="width:200px;">

    </select>
    <input name="lblHiddenUnitType" id="lblHiddenUnitType" type="hidden"
    size="14" />
    <script language='javascript'>
    function ConfirmDeleteImage()
    {
    var result;
    var cbo = document.getElementById('cboUnitTypes');
    if (cbo.options.length <= 0) return false;

    if (document.all['lblHiddenUnitType'].value != '0'||
    document.all['lblHiddenUnitType'].value >= 0 ||
    document.all['lblHiddenUnitType'].value != null||
    document.all['lblHiddenUnitType'].value != '')

    {
    result= confirm('Existing Image(s) will be replaced with the new
    ones.Do you want to continue?');
    }
    if(result == false)
    {
    document.all['cboUnitTypes'].onchange = null;
    document.all['cboUnitTypes'].value =
    document.all['lblHiddenUnitType'].value;
    document.all['cboUnitTypes'].onchange = ConfirmDeleteImage;
    }
    else
    {
    document.all['cboUnitTypes'].onchange = null;
    document.all['lblHiddenUnitType'].value =
    document.all['cboUnitTypes'].value;
    document.all['cboUnitTypes'].onchange = ConfirmDeleteImage;
    __doPostBack('cboUnitTypes','');
    }
    return result;
    }
    </script>
    -----
    I am working for IE, not for Firefox.
     
    CreativeMind, Jun 12, 2008
    #2
    1. Advertising

  3. CreativeMind

    CreativeMind Guest

    one more thing, dropdownlist cbounittype is populated from db but
    depending upon another dropdownlist's selected index changed.
     
    CreativeMind, Jun 12, 2008
    #3
  4. CreativeMind

    SAM Guest

    CreativeMind a écrit :
    >
    > i face an error describing 'cbounittypes is either null or
    > not an object' when i see view source, firefox and IE showing
    > different source code.firefox is showing right. but IE not. what's
    > reason??
    >
    > ----- viewsource using firefox
    >
    > <select name="cboUnitTypes" onchange="javascript:return
    > ConfirmDeleteImage();__doPostBack('cboUnitTypes','')"
    > language="javascript" id="cboUnitTypes"
    > class="TextFieldNormalForProperty">


    Si ça pouvait être rangé lisiblement ! ?

    <select name="cboUnitTypes" id="cboUnitTypes"
    class="TextFieldNormalForProperty"
    onchange="return ConfirmDeleteImage();
    __doPostBack('cboUnitTypes','');">

    something here seems missing ...
    as soon as the confirm is returned, the doPostBack can't fire.

    onchange="if(ConfirmDeleteImage())
    return __doPostBack(this.id,'');"


    > ----- viewsource using IE
    >
    > <select name="cboUnitTypes" onchange="javascript:return
    > ConfirmDeleteImage();__doPostBack('cboUnitTypes','')"
    > language="javascript" id="cboUnitTypes"
    > class="TextFieldNormalForProperty" style="width:200px;">


    IE has a style attribute for the select that Fx hasn't ?
    You're sure ?
    Something writes this attribute specially for IE ?


    Why do you use :
    javascript: in onchange="javascript:blah
    and why do you add :
    language="javascript"

    --
    sm
     
    SAM, Jun 12, 2008
    #4
  5. CreativeMind

    SAM Guest

    CreativeMind a écrit :
    > thx.
    > error message is no more raising.
    >> As for the error you're seeing. If you post the Javascript that's
    >> generating this error, we'll have a better chance of helping you

    > ----
    > but i can't my dropdownlist values in IE.
    > here is complete info.
    >
    > <select name="cboUnitTypes" onchange="javascript:return
    > ConfirmDeleteImage();__doPostBack('cboUnitTypes','')"
    > language="javascript" id="cboUnitTypes"
    > class="TextFieldNormalForProperty" style="width:200px;">
    >
    > </select>


    > I am working for IE, not for Firefox.


    ... ????? ...

    Poor IE ! and poor Opera !



    <script type='text/javascript'>
    function ConfirmDeleteImage()
    {
    var result;
    var cbo = document.all?
    document.all['cboUnitTypes'] :
    document.getElementById?
    document.getElementById('cboUnitTypes') :
    document.myForm.cboUnitTypes;
    if (cbo.options.length <= 0) return false;

    if (document.all) {
    var hide = document.all['lblHiddenUnitType'];
    if( hide.value != null && hide.value > 0 )
    {
    result= confirm('Existing Image(s) will be replaced with the '+
    'new one(s).\nDo you want to continue?');
    if(result == false)
    {
    cbo.onchange = null;
    cbo.value = hide.value; // that works with IE ?
    // cbo.selectedIndex = hide.value;
    cbo.onchange = ConfirmDeleteImage;
    }
    else
    {
    cbo.onchange = null;
    hide.value = cbo.value;
    cbo.onchange = ConfirmDeleteImage;
    __doPostBack('cboUnitTypes',''); // doPostBack will no more
    // be in the onchange
    }
    return result;
    }
    else
    if (hide.value != null)
    {
    alert('what do you want to do ?');
    }
    }
    }
    </script>


    version #2 :


    <script type='text/javascript'>
    function ConfirmDeleteImage()
    {
    var cbo = document.all?
    document.all['cboUnitTypes'] :
    document.getElementById?
    document.getElementById('cboUnitTypes') :
    document.myForm.cboUnitTypes;
    if (cbo.options.length <= 0) return false;

    if (document.all) {
    var hide = document.all['lblHiddenUnitType'];
    if( hide.value != null)
    {
    hide.value = cbo.value;
    if( confirm('Existing Image(s) will be replaced with the '+
    'new one(s).\nDo you want to continue?') )
    {
    cbo.onchange = null;
    cbo.onchange = ConfirmDeleteImage;
    __doPostBack('cboUnitTypes',''); // doPostBack will no more
    return true; // be in the onchange
    }
    cbo.onchange = null;
    cbo.selectedIndex = hide.value;
    cbo.onchange = ConfirmDeleteImage;
    return false;
    }
    }
    }
    </script>


    --
    sm
     
    SAM, Jun 12, 2008
    #5
  6. CreativeMind

    CreativeMind Guest

    On Jun 12, 9:42 pm, SAM <>
    wrote:
    > CreativeMind a écrit :
    >
    > > thx.
    > > error message is no more raising.
    > >> As for the error you're seeing. If you post the Javascript that's
    > >> generating this error, we'll have a better chance of helping you

    > > ----
    > > but i can't my dropdownlist values in IE.
    > > here is complete info.

    >
    > > <select name="cboUnitTypes" onchange="javascript:return
    > > ConfirmDeleteImage();__doPostBack('cboUnitTypes','')"
    > > language="javascript" id="cboUnitTypes"
    > > class="TextFieldNormalForProperty" style="width:200px;">

    >
    > > </select>
    > > I am working for IE, not for Firefox.

    >
    > ... ????? ...
    >
    > Poor IE ! and poor Opera !
    >
    > <script type='text/javascript'>
    > function ConfirmDeleteImage()
    > {
    > var result;
    > var cbo = document.all?
    > document.all['cboUnitTypes'] :
    > document.getElementById?
    > document.getElementById('cboUnitTypes') :
    > document.myForm.cboUnitTypes;
    > if (cbo.options.length <= 0) return false;
    >
    > if (document.all) {
    > var hide = document.all['lblHiddenUnitType'];
    > if( hide.value != null && hide.value > 0 )
    > {
    > result= confirm('Existing Image(s) will be replaced with the '+
    > 'new one(s).\nDo you want to continue?');
    > if(result == false)
    > {
    > cbo.onchange = null;
    > cbo.value = hide.value; // that works with IE ?
    > // cbo.selectedIndex = hide.value;
    > cbo.onchange = ConfirmDeleteImage;
    > }
    > else
    > {
    > cbo.onchange = null;
    > hide.value = cbo.value;
    > cbo.onchange = ConfirmDeleteImage;
    > __doPostBack('cboUnitTypes',''); // doPostBack will no more
    > // be in the onchange
    > }
    > return result;
    > }
    > else
    > if (hide.value != null)
    > {
    > alert('what do you want to do ?');
    > }
    > }
    > }
    > </script>
    >
    > version #2 :
    >
    > <script type='text/javascript'>
    > function ConfirmDeleteImage()
    > {
    > var cbo = document.all?
    > document.all['cboUnitTypes'] :
    > document.getElementById?
    > document.getElementById('cboUnitTypes') :
    > document.myForm.cboUnitTypes;
    > if (cbo.options.length <= 0) return false;
    >
    > if (document.all) {
    > var hide = document.all['lblHiddenUnitType'];
    > if( hide.value != null)
    > {
    > hide.value = cbo.value;
    > if( confirm('Existing Image(s) will be replaced with the '+
    > 'new one(s).\nDo you want to continue?') )
    > {
    > cbo.onchange = null;
    > cbo.onchange = ConfirmDeleteImage;
    > __doPostBack('cboUnitTypes',''); // doPostBack will no more
    > return true; // be in the onchange
    > }
    > cbo.onchange = null;
    > cbo.selectedIndex = hide.value;
    > cbo.onchange = ConfirmDeleteImage;
    > return false;
    > }
    > }
    > }
    > </script>
    >
    > --
    > sm


    thanx a lot of you SAM, that solved my problem. could you please tell
    about why doesn't IE's viewsource show values of dropdownlist unlike
    FF.once again thanx a lot.
     
    CreativeMind, Jun 12, 2008
    #6
  7. CreativeMind

    SAM Guest

    CreativeMind a écrit :
    >
    > thanx a lot of you SAM, that solved my problem.
    > could you please tell about why doesn't IE's viewsource show values
    > of dropdownlist unlike FF.


    No, I can't :
    - I haven't IE (IE doesn't run on Mac)
    - I do not know what you want to do
    And even I'm surprised the function solved your problem as I don't
    understand you need a hidden field nor why you have to modify the
    onchange, and all that only for IE

    Dan Rummey answered you the why :
    if the options are filled by JavaScript, IE will not show them in the
    view-source (of course there is nothing of that in the html code !)
    Don't you see or read all answers to your question ?

    As already asked : put a demo of the trouble somewhere on a server
    and give its url for we could see of what you are speaking.

    Without the code to fill up the options, nobody can see what's wrong.


    <script type='text/javascript'>

    function $(id) // multi browser getter of an element
    {
    return typeof id != 'string'? id :
    document.getElementById?
    document.getElementById(id) :
    document.all?
    document.all[id] :
    document.forms[0].elements[id]; // suppose an alone form
    }

    function ConfirmDeleteImage() // would have to work with any browser
    {
    var cbo = $('cboUnitTypes');
    if (cbo.options.length <= 0)
    {
    alert('I do not understand why the function did fire');
    return false;
    }
    if (cbo.selectedIndex == 0)
    {
    alert('Choice another item in the list');
    return false;
    }
    if(confirm('Existing Image(s) will be replaced with the '+
    'new one(s).\nDo you want to continue?') )
    {
    __doPostBack('cboUnitTypes','');
    return true;
    }
    return false;
    }
    </script>

    --
    sm
     
    SAM, Jun 12, 2008
    #7
  8. CreativeMind

    RobG Guest

    On Jun 13, 8:59 am, SAM <>
    wrote:
    [...]
    > <script type='text/javascript'>
    >
    > function $(id) // multi browser getter of an element


    There has recently been discussion about using $ as a function name,
    it is not considered a good idea around here:

    "Replacing document.getElementById with $ (dollar sign)"
    <URL
    http://groups.google.com.au/group/c...tById with $ (dollar sign) #ed508f8184cd5a4e
    >



    > {
    > return typeof id != 'string'? id :
    > document.getElementById?
    > document.getElementById(id) :
    > document.all?
    > document.all[id] :
    > document.forms[0].elements[id]; // suppose an alone form
    > }


    A more efficient way is to test the supported features and create an
    appropriate function up front, then you don't have to test for
    getElementById and all every time, e.g.

    var getElement = (function() {
    if (document) {
    if (document.getElementById) {
    return function(id) {
    return (typeof id == 'string')? document.getElementById(id) :
    id;
    }
    } else if (document.all) {
    return function(id) {
    return (typeof id == 'string')? document.all(id) : id;
    }
    }
    }
    })();

    There are more detailed feature tests (search the archives) that can
    be applied if required.


    > function ConfirmDeleteImage() // would have to work with any browser
    > {
    > var cbo = $('cboUnitTypes');
    > if (cbo.options.length <= 0)


    I can't imagine a scenario where the length of an options collection
    can be less than zero. Anyway, the length of an options collection is
    an unsigned long so it can't be negative - providing the UA is
    standards comliant of course. :)

    <URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#HTMLOptionsCollection-length
    >



    > {
    > alert('I do not understand why the function did fire');
    > return false;
    > }
    > if (cbo.selectedIndex == 0)


    This test should be less than or equal to zero since the selectedIndex
    should be -1 if no option has been selected.

    <URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-85676760 >


    > {
    > alert('Choice another item in the list');


    Choose? :)


    --
    Rob
     
    RobG, Jun 13, 2008
    #8
  9. CreativeMind

    SAM Guest

    RobG a écrit :
    > On Jun 13, 8:59 am, SAM <>
    > wrote:
    > [...]
    >> <script type='text/javascript'>
    >>
    >> function $(id) // multi browser getter of an element

    >
    > There has recently been discussion about using $ as a function name,
    > it is not considered a good idea around here:
    >
    > "Replacing document.getElementById with $ (dollar sign)"
    > <URL
    > http://groups.google.com.au/group/c...tById with $ (dollar sign) #ed508f8184cd5a4e


    That overall seems to discus about saving few octets and the almost
    reserved sign $ (and it's use in most libraries)
    Here the idea is to "translate" GBEI and I think it's a good progress
    relatively to the initial code from OP.

    >> {
    >> return typeof id != 'string'? id :
    >> document.getElementById?
    >> document.getElementById(id) :
    >> document.all?
    >> document.all[id] :
    >> document.forms[0].elements[id]; // suppose an alone form
    >> }

    >
    > A more efficient way is to test the supported features and create an
    > appropriate function up front, then you don't have to test for
    > getElementById and all every time, e.g.


    You mean with this code the call to getElement('anId')
    will no more run the function (its if then or) ?
    The translation is made once for all the page.

    > var getElement = (function() {
    > if (document) {
    > if (document.getElementById) {
    > return function(id) {
    > return (typeof id == 'string')? document.getElementById(id) :
    > id;
    > }
    > } else if (document.all) {
    > return function(id) {
    > return (typeof id == 'string')? document.all(id) : id;
    > }
    > }
    > }
    > })();



    >> function ConfirmDeleteImage() // would have to work with any browser
    >> {
    >> var cbo = $('cboUnitTypes');
    >> if (cbo.options.length <= 0)

    >
    > I can't imagine a scenario where the length of an options collection


    I think it was a test to see if the JS did fill up the options
    (not html coded)

    > can be less than zero. Anyway, the length of an options collection is
    > an unsigned long so it can't be negative - providing the UA is
    > standards comliant of course. :)


    Not a real problem the goal is the 0 value

    >> {
    >> alert('I do not understand why the function did fire');
    >> return false;
    >> }
    >> if (cbo.selectedIndex == 0)

    >
    > This test should be less than or equal to zero since the selectedIndex
    > should be -1 if no option has been selected.


    without selection no onchange, no ?
    so that can never be -1 if a change was made

    >> {
    >> alert('Choice another item in the list');

    >
    > Choose? :)


    may be, may be :)

    --
    sm
     
    SAM, Jun 13, 2008
    #9
  10. RobG wrote:
    > SAM wrote:
    > [...]
    >> <script type='text/javascript'>
    >>
    >> function $(id) // multi browser getter of an element

    > [...]
    >> {
    >> return typeof id != 'string'? id :
    >> document.getElementById?
    >> document.getElementById(id) :
    >> document.all?
    >> document.all[id] :
    >> document.forms[0].elements[id]; // suppose an alone form
    >> }

    >
    > A more efficient way is to test the supported features and create an
    > appropriate function up front, then you don't have to test for
    > getElementById and all every time, e.g.
    >
    > var getElement = (function() {
    > if (document) {
    > if (document.getElementById) {
    > return function(id) {
    > return (typeof id == 'string')? document.getElementById(id) :

    ^^^^^^^^^^^^^^^^^^^^^^^^
    > id;
    > }
    > } else if (document.all) {
    > return function(id) {
    > return (typeof id == 'string')? document.all(id) : id;

    ^^^^^^^^^^^^^^^^^^^^^^^^
    > }
    > }
    > }
    > })();


    One would buy efficiency with runtime flexibility, of course.

    However, I do not see why a user-defined method should waste runtime for
    supporting the incompetence of the person calling it. IMHO this function
    should expect a string value (or something convertible to that, but this
    should be left to the DOM API) and nothing else.


    PointedEars
    --
    Prototype.js was written by people who don't know javascript for people
    who don't know javascript. People who don't know javascript are not
    the best source of advice on designing systems that use javascript.
    -- Richard Cornford, cljs, <f806at$ail$1$>
     
    Thomas 'PointedEars' Lahn, Jun 13, 2008
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    16
    Views:
    7,342
    Mike Schilling
    Oct 12, 2005
  2. Replies:
    5
    Views:
    26,693
    Mike Schilling
    Mar 29, 2006
  3. Cirene
    Replies:
    1
    Views:
    816
    Alexey Smirnov
    Jun 9, 2008
  4. putty
    Replies:
    1
    Views:
    259
    putty
    Apr 5, 2005
  5. Tim Platt

    XMLHTTP - null is null or not an object

    Tim Platt, Jun 4, 2007, in forum: Javascript
    Replies:
    0
    Views:
    178
    Tim Platt
    Jun 4, 2007
Loading...

Share This Page