473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Undefined variable error

Hi! Does anyone know why the onclick in the following popup menu gives
the error:"Val is undefined"? Does it have something to do with the
fact that it is called within the variable tablePop? Because it IS
displayed properly as part of the popup text, where it is called
outside the single quotation marks (see [***]). It is only in the
onclick that it's causing problems. Who can help me?

function dopopup(x,y) {
var Val=event.srcElement.href1.substring(0,(event.srcE lement.href1.length-1));
var Field=event.srcElement.href2.substring(1,(event.sr cElement.href2.length-1));
var tablePop='';
tablePop+='<TABLE oncontextmenu=\"return false\";>';
tablePop+='<SCRIPT LANGUAGE="JavaScript">\n';
tablePop+='\n<!--\n';
tablePop+='window.onerror=null;\n';
tablePop+='/-->\n';
tablePop+='<\/SCRIPT>\n';
tablePop+='<TR><TD ONCLICK="renderData(Val,Field);">&nbsp;Filter op
'[***] + Field + ' is ' + Val +'</TD></TR>';
tablePop+='<TR><TD>&nbsp;Filter op ' + Field + ' is NIET '+
Val +'</TD></TR>';
tablePop+='<\/TABLE>';
var oPopupBody = oPopup.document.body;
oPopupBody.innerHTML = tablePop;
oPopup.show(x, y, 140, 220, document.body);
}

function renderData(filterValue,filterField)
{
alert(filterValue);
alert(filterField);
}
Jul 23 '05 #1
10 5248
> var
Val=event.srcElement.href1.substring(0,(event.srcE lement.href1.length-1));

have you tried alerting the value of Val ? to see what it holds?

thx stu

"Sharon" <es*****@hotmail.com> wrote in message
news:2b**************************@posting.google.c om...
Hi! Does anyone know why the onclick in the following popup menu gives
the error:"Val is undefined"? Does it have something to do with the
fact that it is called within the variable tablePop? Because it IS
displayed properly as part of the popup text, where it is called
outside the single quotation marks (see [***]). It is only in the
onclick that it's causing problems. Who can help me?

function dopopup(x,y) {
var Val=event.srcElement.href1.substring(0,(event.srcE lement.href1.length-1)); var Field=event.srcElement.href2.substring(1,(event.sr cElement.href2.length-1)); var tablePop='';
tablePop+='<TABLE oncontextmenu=\"return false\";>';
tablePop+='<SCRIPT LANGUAGE="JavaScript">\n';
tablePop+='\n<!--\n';
tablePop+='window.onerror=null;\n';
tablePop+='/-->\n';
tablePop+='<\/SCRIPT>\n';
tablePop+='<TR><TD ONCLICK="renderData(Val,Field);">&nbsp;Filter op
'[***] + Field + ' is ' + Val +'</TD></TR>';
tablePop+='<TR><TD>&nbsp;Filter op ' + Field + ' is NIET '+
Val +'</TD></TR>';
tablePop+='<\/TABLE>';
var oPopupBody = oPopup.document.body;
oPopupBody.innerHTML = tablePop;
oPopup.show(x, y, 140, 220, document.body);
}

function renderData(filterValue,filterField)
{
alert(filterValue);
alert(filterField);
}

Jul 23 '05 #2
Lee
Sharon said:

Hi! Does anyone know why the onclick in the following popup menu gives
the error:"Val is undefined"? Does it have something to do with the
fact that it is called within the variable tablePop? Because it IS
displayed properly as part of the popup text, where it is called
outside the single quotation marks (see [***]). It is only in the
onclick that it's causing problems. Who can help me? var Val=event.srcElement.href1.substring(0,(event.srcE lement.href1.length-1)); tablePop+='<TR><TD ONCLICK="renderData(Val,Field);">&nbsp;Filter op


Val is a local variable within this function.
It has no value anyplace else.
The onclick handler is called someplace else.

Val is not dereferenced (called) within the variable tablePop.
Within that string, it's just three characters with no special
meaning. If you want the string to contain the value of Val,
instead of just the three characters "Val", you have to insert
the value of the string, instead of its name:

tablePop+='<TR><TD ONCLICK="renderData(' + Val + ',' + Field + ');">'

Jul 23 '05 #3
Sharon wrote:
<snip>

function dopopup(x,y) {
var Val=event.srcElement.href1.substring(0,(event.srcE lement.href1.length-1));
var Field=event.srcElement.href2.substring(1,(event.sr cElement.href2.length-1));


var
Val=event.srcElement.href1.substring(0,(event.srcE lement.href1.length-1));

Isn't that redundant?
Val=event.srcElement.href1

Or am I missing something?

Mick
Jul 23 '05 #4
Yup, I have actually tried that. When I alert Val and Field right after
I declare them or at the end, everything's fine > the values are alerted
correctly. Just like they are displayed correctly in the popup. It's
just within the single quotation marks, so within the other variable,
that they aren't defined according to the browser. Thanks!
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #5
Lee <RE**************@cox.net> wrote in message news:<cb*********@drn.newsguy.com>...

Val is not dereferenced (called) within the variable tablePop.
Within that string, it's just three characters with no special
meaning. If you want the string to contain the value of Val,
instead of just the three characters "Val", you have to insert
the value of the string, instead of its name:
tablePop+='<TR><TD ONCLICK="renderData(' + Val + ',' + Field + ');">'

Thanks, I did, but now a new version of the error message appears:
this time it says "error:[value of the variable] is undefined", so
it's not the name of the variable, the three letters 'Val' anymore
that aren't recognized, it's the value of the variable 'Val' that is
undefined. So if the variable "Val" has e.g. value "Calcutta", the
error message says "Calcutta is undefined". How can I get the variable
passed to the function renderData? Thanks in advance!
Jul 23 '05 #6
Lee
Sharon said:

Lee <RE**************@cox.net> wrote in message
news:<cb*********@drn.newsguy.com>...

Val is not dereferenced (called) within the variable tablePop.
Within that string, it's just three characters with no special
meaning. If you want the string to contain the value of Val,
instead of just the three characters "Val", you have to insert
the value of the string, instead of its name:
tablePop+='<TR><TD ONCLICK="renderData(' + Val + ',' + Field + ');">'

Thanks, I did, but now a new version of the error message appears:
this time it says "error:[value of the variable] is undefined", so
it's not the name of the variable, the three letters 'Val' anymore
that aren't recognized, it's the value of the variable 'Val' that is
undefined. So if the variable "Val" has e.g. value "Calcutta", the
error message says "Calcutta is undefined". How can I get the variable
passed to the function renderData? Thanks in advance!


I was thinking that the value was a number.
Since it's a string, it needs to be quoted when used as an
argument to renderData():

tablePop+='<TR><TD ONCLICK="renderData(\'' + Val + '\',\'' + Field + '\');">'

Jul 23 '05 #7
Thanks, I had actually figured that out myself after some logical
thinking, but it still won't work. This is what my function looks like:

function dopopup(Val,Field,x,y) {
var popCode="";
popCode+='<SCRIPT LANGUAGE="JavaScript">\n';
popCode+='\n<!--\n';
popCode+='window.onerror=null;\n';
popCode+='/-->\n';
popCode+='<\/SCRIPT>\n';
popCode+='<tr><td'
popCode+=' onClick="renderData(\'' + Val +'\');">';
popCode+='Filter op: '+Field+' is '+Val+'</td></tr>\n';
popCode+='<tr><td';
popCode+=' onClick="renderData(\'' + Field +'\');">';
popCode+='Filter op: '+Field+' is '+Val+'</td></tr>\n';
popCode+='</table>\n';
var oPopupBody = oPopup.document.body;
oPopupBody.innerHTML = popCode;
oPopup.show(x, y, 140, 220, document.body);
}

When I click on the first <td>, I get the error "Object expected" for
line 12, when I click on the second one I get the same error for line
13. I don't know if the line numbers are accurate, though. And I don't
have a clue as to what could cause the error...Any help is greatly
appreciated, thanks! Sharon
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #8
Sharon Steringa wrote:
Thanks, I had actually figured that out myself after some logical
thinking, but it still won't work. This is what my function looks
like:

function dopopup(Val,Field,x,y) {
var popCode="";
popCode+='<SCRIPT LANGUAGE="JavaScript">\n';
The language attribute is deprecated in current HTML versions (and
absent from the HTML 4.01 strict DTD). The TYPE attribute is required
for valid HTML, so:-

popCode+='<SCRIPT TYPE="text/javascript">\n';
popCode+='\n<!--\n'; ^^^^
Do you understand why you are doing that?

In an age long past, when client-side scripting was so new that many
browsers in use did not know how to handle SCRIPT elements, it was used
as a mans of "hiding" scripts from those browsers so that they would not
display the SCRIPT code as contents of a page. These days even browsers
that cannot execute scripts know enough to ignore SCRIPT elements on
their own and so this is no longer needed. Unfortunately the practice
has propagated through the generations as a sort of folk-law practised
by people who have not bothered to understand why they are doing what
they are doing.

However, even if the practice was still valid there would be no point in
attempting to hide the contents of a SCRIPT element when that element
was being created with a script as a browser that could not understand
the SCRIPT element could never generate it.
popCode+='window.onerror=null;\n';
The default onerror handler is null or undefined on all browsers. There
is little point in actively setting it to that value unless it has had
an alternative handler assigned first.
popCode+='/-->\n';
The "hiding form older browsers" technique calls for the closing "HTML
comment" tag use in a script to follow a javascript end-of-line comment,
so that it will not be interpreted as a syntax error. The javascript
end-of-line comment is _two_ forward slashes - // - not one. The script
written above is - divided by, pre/post-decrement, greater than - and
represents a syntax error in javascript as none of those operators have
operands.

This entire SCRIPT element seems superfluous.
popCode+='<\/SCRIPT>\n';
popCode+='<tr><td'
popCode+=' onClick="renderData(\'' + Val +'\');">';

<snip>

This - renderDate - function does not feature in the code you have just
posted but it is probably the object being referred to as "Object
expected". Probably it is not defined within the scope of - oPopup - and
would need a more qualified reference to access it. But nobody will be
able to tell you how to do that without seeing/knowing the full context.

Richard.
Jul 23 '05 #9
Thanks, Richard! You're right, I didn't understand why I was doing that.
I'm new at this Javascript-thing and I was happy to find a piece of code
somewhere and I'm now trying to change it so it'll work for my
application, which is mainly XML/XSL (that's where my skills lie). This
is also the reason why I don't have full control over my script and why
I slightly panic over my error messages...I had posted the renderData
function earlier in this thread, together with the other two functions I
use. Since it was only the dopopup-function I amended, that's the only
one I posted again. But I'll post the whole thing again for you:

function dopopup(Val,Field,x,y) {
var popCode="";
popcode+='<script LANGUAGE="JavaScript">\n';
popcode+='\n<!--\n';
popCode+='window.onerror=null;\n';
popCode+='/-->\n';
popcode+='<\/script>\n';
popcode+='<tr><td'
popCode+=' onClick="renderData(\'' + Val +'\');">';
popCode+='Filter op: '+Field+' is '+val+'</td></tr>\n';
popcode+='<tr><td';
popCode+=' onClick="renderData(\'' + Field +'\');">';
popCode+='Filter op: '+Field+' is '+val+'</td></tr>\n';
popcode+='</table>\n';
var oPopupBody = oPopup.document.body;
oPopupBody.innerHTML = popCode;
oPopup.show(x, y, 140, 220, document.body);
}

function renderData(filterField){
alert("Joepie hij doet 't!");
alert(filterField);
}

The two functions are in the same external .js file. I hope you or
anyone else will be able to help me, and/or share some more
javascript-knowledge because I find it very interesting and I really
want to get this thing to work! Thanks, Sharon

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #10
Lee
Sharon Steringa said:

Thanks, Richard! You're right, I didn't understand why I was doing that.
I'm new at this Javascript-thing and I was happy to find a piece of code
somewhere and I'm now trying to change it so it'll work for my
application, which is mainly XML/XSL (that's where my skills lie). This
is also the reason why I don't have full control over my script and why
I slightly panic over my error messages...I had posted the renderData
function earlier in this thread, together with the other two functions I
use. Since it was only the dopopup-function I amended, that's the only
one I posted again. But I'll post the whole thing again for you:

function dopopup(Val,Field,x,y) {
var popCode="";
popcode+='<script LANGUAGE="JavaScript">\n';
popcode+='\n<!--\n';
popCode+='window.onerror=null;\n';
popCode+='/-->\n';
popcode+='<\/script>\n';
popcode+='<tr><td'
popCode+=' onClick="renderData(\'' + Val +'\');">';
popCode+='Filter op: '+Field+' is '+val+'</td></tr>\n';
popcode+='<tr><td';
popCode+=' onClick="renderData(\'' + Field +'\');">';
popCode+='Filter op: '+Field+' is '+val+'</td></tr>\n';
popcode+='</table>\n';
var oPopupBody = oPopup.document.body;
oPopupBody.innerHTML = popCode;
oPopup.show(x, y, 140, 220, document.body);
}


Javascript is case sensitive, so popcode is not the
same as popCode, and val is not the same as Val.

You're missing the opening tag for your <table>.

Your <script> tag should have a type attribute: type="text/javascript"

There's no need for the <!-- --> comments.

It's generally a bad idea to try to defeat the onError handler.

Jul 23 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dan Finn | last post by:
OpenBSD 3.2 Apache 1.3.26 PHP 4.3.4 PHP-Nuke 6.9 getting these in the apache error log: Sun Nov 16 20:20:16 2003] PHP Notice: Undefined variable: HTTP_USER_AGENT in...
3
by: Jason | last post by:
hello, i am new to PHP, so go easy. I am using the examples in the book: PHP: Your Visual Blueprint For Creating Open Source, Server Side Content In the section where they talk about...
3
by: Martin | last post by:
I'm getting PHP Notice: Undefined variable: db_list in C:\mypage.php on line xx when I use the following code: <?php $conn = @mysql_connect( "localhost", "myname", "mypassword" ) or die(...
10
by: Chuck | last post by:
Hi! Any ideas as to how I can get ride of the script error undefined variable "Exp_Month"? I am trying to get this drop down list to default to the current month as opposed to 01. Thank...
4
by: Chris Beall | last post by:
If you want your code to be bulletproof, do you have to explicitly check for the existence of any possibly-undefined variable? Example: window.outerHeight is defined by some browsers, but not...
1
by: rizk | last post by:
I'm getting the following error when i load my page 'bak_up' is undefeined. Any body can help!
6
by: Jeremy Felt | last post by:
Newbie here. I'm sure I'm missing something EXTREMELY simple, but an hour of searching has led to nothing. I'm playing around with ajax and trying to pass a variable to a function. If I do:...
2
by: Bob Bruyn | last post by:
I've recently installed Apache 2 and php 5.2 on my WIndows XP machine. Everything is up and running. I'm passing some vars via the URL. It works fine online:...
1
by: bob johnson | last post by:
Notice: Undefined variable: db_host in C:\wamp\www\cbmall\index.php on line 7 Notice: Undefined variable: db_user in C:\wamp\www\cbmall\index.php on line 7 Notice: Undefined variable: db_pass...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.