message of 'is null or not an object'

C

CreativeMind

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>
 
C

CreativeMind

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>
 
C

CreativeMind

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

SAM

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"
 
S

SAM

CreativeMind a écrit :
thx.
error message is no more raising.
----
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>
 
C

CreativeMind

CreativeMind a écrit :
thx.
error message is no more raising.
<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>

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.
 
S

SAM

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>
 
R

RobG

On Jun 13, 8:59 am, SAM <[email protected]>
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.

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

Choose? :)
 
S

SAM

RobG a écrit :
On Jun 13, 8:59 am, SAM <[email protected]>
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;
}
}
}
})();


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

may be, may be :)
 
T

Thomas 'PointedEars' Lahn

RobG said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,006
Latest member
LauraSkx64

Latest Threads

Top