HighDots Forums  

message of 'is null or not an object'

Javascript JavaScript language (comp.lang.javascript)


Discuss message of 'is null or not an object' in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
CreativeMind
 
Posts: n/a

Default message of 'is null or not an object' - 06-12-2008 , 08:40 AM






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>

Reply With Quote
  #2  
Old   
Dan Rumney
 
Posts: n/a

Default Re: message of 'is null or not an object' - 06-12-2008 , 08:52 AM






CreativeMind wrote:
Quote:
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"
language is not a property of a SELECT element. This should be removed

Quote:
<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
Does your page do any DOM manipulation? More specifically, are the
option elements generated on the fly by Javascript?

If so, that's why. When you view source with MSIE, you only get to see
the source that the server returned to your original GET request.

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


Reply With Quote
  #3  
Old   
CreativeMind
 
Posts: n/a

Default Re: message of 'is null or not an object' - 06-12-2008 , 09:28 AM



thx.
error message is no more raising.
Quote:
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.


Reply With Quote
  #4  
Old   
CreativeMind
 
Posts: n/a

Default Re: message of 'is null or not an object' - 06-12-2008 , 09:44 AM



one more thing, dropdownlist cbounittype is populated from db but
depending upon another dropdownlist's selected index changed.

Reply With Quote
  #5  
Old   
Dan Rumney
 
Posts: n/a

Default Re: message of 'is null or not an object' - 06-12-2008 , 09:51 AM



CreativeMind wrote:
Quote:
one more thing, dropdownlist cbounittype is populated from db but
depending upon another dropdownlist's selected index changed.
So, the dropdown list is being populated by Javascript, is that correct?

If so, you need to take a look at *that* code and find out why it's not
working.

Can you make this page available on the internet?


Reply With Quote
  #6  
Old   
SAM
 
Posts: n/a

Default Re: message of 'is null or not an object' - 06-12-2008 , 10:34 AM



CreativeMind a écrit :
Quote:
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,'');"


Quote:
----- 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


Reply With Quote
  #7  
Old   
SAM
 
Posts: n/a

Default Re: message of 'is null or not an object' - 06-12-2008 , 11:42 AM



CreativeMind a écrit :
Quote:
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




Reply With Quote
  #8  
Old   
CreativeMind
 
Posts: n/a

Default Re: message of 'is null or not an object' - 06-12-2008 , 12:31 PM



On Jun 12, 9:42 pm, SAM <stephanemoriaux.NoAd... (AT) wanadoo (DOT) fr.invalid>
wrote:
Quote:
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.


Reply With Quote
  #9  
Old   
SAM
 
Posts: n/a

Default Re: message of 'is null or not an object' - 06-12-2008 , 05:59 PM



CreativeMind a écrit :
Quote:
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


Reply With Quote
  #10  
Old   
RobG
 
Posts: n/a

Default Re: message of 'is null or not an object' - 06-12-2008 , 07:42 PM



On Jun 13, 8:59 am, SAM <stephanemoriaux.NoAd... (AT) wanadoo (DOT) fr.invalid>
wrote:
[...]
Quote:
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/co...8f81 84cd5a4e
Quote:

Quote:
{
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.


Quote:
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-HTM...lection-length
Quote:

Quote:
{
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-HTM...ml#ID-85676760 >


Quote:
{
alert('Choice another item in the list');
Choose? :-)


--
Rob


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.