473,324 Members | 2,166 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,324 software developers and data experts.

Calling a function within itself (kindof recursion but ...)

gf
<script>
function testme(testvar) {
if (testvar=='1') {
alert('testvar=1');
document.open();
document.write('This is just some text<br /><br />");
document.write('<a href="javascript:testme(\'2\');" >Next >>&nbsp;</a>');
document.close();
}
else if (testvar=='2') {
alert('testvar=2');
}
}
</script>
<a href="javascript:testme('1');" >Next >>&nbsp;</a>
It seems that this should work, but alas, it doesn't. What I am emulating
in this example is a case where you start off with a hyperlink that calls
TESTME and produces another hyperlink. When you click on the hyperlink, it
errors out and produces "object expected" in IE and "Error: callHelp is not
defined" in NS. Why is it saying callHelp is not defined and how do I fix
this?

Thanks.
Jul 23 '05 #1
4 1874

"gf" <gf******@earthlink.net> wrote in message
news:dS*****************@newsread1.news.pas.earthl ink.net...
<script>
function testme(testvar) {
if (testvar=='1') {
alert('testvar=1');
document.open();
document.write('This is just some text<br /><br />");
document.write('<a href="javascript:testme(\'2\');" >Next
&nbsp;</a>'); document.close();
}
else if (testvar=='2') {
alert('testvar=2');
}
}
</script>
<a href="javascript:testme('1');" >Next >>&nbsp;</a>
It seems that this should work, but alas, it doesn't. What I am emulating
in this example is a case where you start off with a hyperlink that calls
TESTME and produces another hyperlink. When you click on the hyperlink,

it errors out and produces "object expected" in IE and "Error: callHelp is not defined" in NS. Why is it saying callHelp is not defined and how do I fix
this?

Thanks.

You just overwrote your entire document, with a new document that has no
script in it... so then
when you click on the link, it has no function to refer to any longer...

If you included the function definition inside the text to be written to the
document, then you might get it to work.

Run this script and view the source; you see what now is in the document;
not much, and certainly no function definition to be called a second time.

It's not entirely clear to me why you would want to do anything quite like
this.. but usually the best way to operate is to put everything inside of a
string, contantinating every new statement into on big string or var, and
then write out the var at the end out to the document with one
document.write statement at the end, like:

var a = "this is some text <br>";

a += "this is some more text too <br>";

a += "this is the final line of text to be written to the document. <br>";

document.write (a);

Also, you might want to write text into a DIV tag, or some other object that
can act as a container so that the rest of your document is not affected
(erased) when you write into it.

Personally, I like looking at this kind of thing in a debugger; it's a
little easier some times to see how things are working when you can watch
the vars change as the script executes, and be able to see into DOM objects
to see if they are null or assigned with ids and values as expected.

http://www.mandala.com/javascript/debug_javascript.html
Javascript Debugging with the MS Script Editor

Ciao,
Jeff




Jul 23 '05 #2
gf
Well, I chastised myself too soon :) Here is more of the real script, so I
do not believe I am overwriting myself.

<script>
function callHelp(page) {
var helpWin =
window.open('','rwh_help','status=1,menubar=0,tool bar=0,width=400,height=600
');
with (helpWin.document) {
open();
writeln('<html><head><title>Help</title></head>');
writeln('<center><a href="http://somedomain.com" target="_blank"><b
style="color:blue;">Test</b></a></center>');
writeln('<br /><table border=1>');
if (page=='main') {
writeln('<tr><td>This is a test</td></tr><tr><td align="right"><a
href="javascript:callHelp(\'page2\');" >Next >>&nbsp;</a></td></tr>');
}
else if (page=='page2') {alert(page);
writeln('page 2');
}
writeln('</table></html>');
close();
return;
}
}
</script>

"Jman" <li***@rock.com> wrote in message
news:40**********@news.athenanews.com...

"gf" <gf******@earthlink.net> wrote in message
news:dS*****************@newsread1.news.pas.earthl ink.net...
<script>
function testme(testvar) {
if (testvar=='1') {
alert('testvar=1');
document.open();
document.write('This is just some text<br /><br />");
document.write('<a href="javascript:testme(\'2\');" >Next
&nbsp;</a>'); document.close();
}
else if (testvar=='2') {
alert('testvar=2');
}
}
</script>
<a href="javascript:testme('1');" >Next >>&nbsp;</a>
It seems that this should work, but alas, it doesn't. What I am emulating in this example is a case where you start off with a hyperlink that calls TESTME and produces another hyperlink. When you click on the hyperlink,

it
errors out and produces "object expected" in IE and "Error: callHelp is

not
defined" in NS. Why is it saying callHelp is not defined and how do I fix this?

Thanks.

You just overwrote your entire document, with a new document that has no
script in it... so then
when you click on the link, it has no function to refer to any longer...

If you included the function definition inside the text to be written to

the document, then you might get it to work.

Run this script and view the source; you see what now is in the document;
not much, and certainly no function definition to be called a second time.

It's not entirely clear to me why you would want to do anything quite like
this.. but usually the best way to operate is to put everything inside of a string, contantinating every new statement into on big string or var, and
then write out the var at the end out to the document with one
document.write statement at the end, like:

var a = "this is some text <br>";

a += "this is some more text too <br>";

a += "this is the final line of text to be written to the document. <br>";

document.write (a);

Also, you might want to write text into a DIV tag, or some other object that can act as a container so that the rest of your document is not affected
(erased) when you write into it.

Personally, I like looking at this kind of thing in a debugger; it's a
little easier some times to see how things are working when you can watch
the vars change as the script executes, and be able to see into DOM objects to see if they are null or assigned with ids and values as expected.

http://www.mandala.com/javascript/debug_javascript.html
Javascript Debugging with the MS Script Editor

Ciao,
Jeff



Jul 23 '05 #3
gf wrote:
Well, I chastised myself too soon :) Here is more of the real script, so I
do not believe I am overwriting myself.

<script>
function callHelp(page) {
var helpWin =
window.open('','rwh_help','status=1,menubar=0,tool bar=0,width=400,height=600
');
with (helpWin.document) {
open();
writeln('<html><head><title>Help</title></head>');
writeln('<center><a href="http://somedomain.com" target="_blank"><b
style="color:blue;">Test</b></a></center>');
writeln('<br /><table border=1>');
if (page=='main') {
writeln('<tr><td>This is a test</td></tr><tr><td align="right"><a
href="javascript:callHelp(\'page2\');" >Next >>&nbsp;</a></td></tr>');
writeln('<tr><td>This is a test</td></tr><tr><td align="right"><a
href="javascript:opener.callHelp(\'page2\');">Next >>&nbsp;</a></td></tr>');
Mick

}
else if (page=='page2') {alert(page);
writeln('page 2');
}
writeln('</table></html>');
close();
return;
}
}
</script>

"Jman" <li***@rock.com> wrote in message
news:40**********@news.athenanews.com...
"gf" <gf******@earthlink.net> wrote in message
news:dS*****************@newsread1.news.pas.eart hlink.net...
<script>
function testme(testvar) {
if (testvar=='1') {
alert('testvar=1');
document.open();
document.write('This is just some text<br /><br />");
document.write('<a href="javascript:testme(\'2\');" >Next

&nbsp;</a>');

document.close();
}
else if (testvar=='2') {
alert('testvar=2');
}
}
</script>
<a href="javascript:testme('1');" >Next >>&nbsp;</a>
It seems that this should work, but alas, it doesn't. What I am
emulating
in this example is a case where you start off with a hyperlink that
calls
TESTME and produces another hyperlink. When you click on the hyperlink,


it
errors out and produces "object expected" in IE and "Error: callHelp is


not
defined" in NS. Why is it saying callHelp is not defined and how do I
fix
this?

Thanks.

You just overwrote your entire document, with a new document that has no
script in it... so then
when you click on the link, it has no function to refer to any longer...

If you included the function definition inside the text to be written to


the
document, then you might get it to work.

Run this script and view the source; you see what now is in the document;
not much, and certainly no function definition to be called a second time.

It's not entirely clear to me why you would want to do anything quite like
this.. but usually the best way to operate is to put everything inside of


a
string, contantinating every new statement into on big string or var, and
then write out the var at the end out to the document with one
document.write statement at the end, like:

var a = "this is some text <br>";

a += "this is some more text too <br>";

a += "this is the final line of text to be written to the document. <br>";

document.write (a);

Also, you might want to write text into a DIV tag, or some other object


that
can act as a container so that the rest of your document is not affected
(erased) when you write into it.

Personally, I like looking at this kind of thing in a debugger; it's a
little easier some times to see how things are working when you can watch
the vars change as the script executes, and be able to see into DOM


objects
to see if they are null or assigned with ids and values as expected.

http://www.mandala.com/javascript/debug_javascript.html
Javascript Debugging with the MS Script Editor

Ciao,
Jeff




Jul 23 '05 #4
gf
Of Course! Thank you so much for slapping me :lol:
"Mick White" <mw******@BOGUSrochester.rr.com> wrote in message
news:Am***************@twister.nyroc.rr.com...
gf wrote:
Well, I chastised myself too soon :) Here is more of the real script, so I do not believe I am overwriting myself.

<script>
function callHelp(page) {
var helpWin =
window.open('','rwh_help','status=1,menubar=0,tool bar=0,width=400,height=600 ');
with (helpWin.document) {
open();
writeln('<html><head><title>Help</title></head>');
writeln('<center><a href="http://somedomain.com" target="_blank"><b
style="color:blue;">Test</b></a></center>');
writeln('<br /><table border=1>');
if (page=='main') {
writeln('<tr><td>This is a test</td></tr><tr><td align="right"><a
href="javascript:callHelp(\'page2\');" >Next >>&nbsp;</a></td></tr>');
writeln('<tr><td>This is a test</td></tr><tr><td align="right"><a

href="javascript:opener.callHelp(\'page2\');">Next >>&nbsp;</a></td></tr>'); Mick

}
else if (page=='page2') {alert(page);
writeln('page 2');
}
writeln('</table></html>');
close();
return;
}
}
</script>

"Jman" <li***@rock.com> wrote in message
news:40**********@news.athenanews.com...
"gf" <gf******@earthlink.net> wrote in message
news:dS*****************@newsread1.news.pas.eart hlink.net...

<script>
function testme(testvar) {
if (testvar=='1') {
alert('testvar=1');
document.open();
document.write('This is just some text<br /><br />");
document.write('<a href="javascript:testme(\'2\');" >Next

>&nbsp;</a>');

document.close();
}
else if (testvar=='2') {
alert('testvar=2');
}
}
</script>
<a href="javascript:testme('1');" >Next >>&nbsp;</a>
It seems that this should work, but alas, it doesn't. What I am


emulating
in this example is a case where you start off with a hyperlink that


calls
TESTME and produces another hyperlink. When you click on the hyperlink,
it

errors out and produces "object expected" in IE and "Error: callHelp is

not

defined" in NS. Why is it saying callHelp is not defined and how do I


fix
this?

Thanks.
You just overwrote your entire document, with a new document that has no
script in it... so then
when you click on the link, it has no function to refer to any longer...

If you included the function definition inside the text to be written to


the
document, then you might get it to work.

Run this script and view the source; you see what now is in the document;not much, and certainly no function definition to be called a second time.
It's not entirely clear to me why you would want to do anything quite likethis.. but usually the best way to operate is to put everything inside of

a
string, contantinating every new statement into on big string or var,

andthen write out the var at the end out to the document with one
document.write statement at the end, like:

var a = "this is some text <br>";

a += "this is some more text too <br>";

a += "this is the final line of text to be written to the document. <br>";
document.write (a);

Also, you might want to write text into a DIV tag, or some other object


that
can act as a container so that the rest of your document is not affected
(erased) when you write into it.

Personally, I like looking at this kind of thing in a debugger; it's a
little easier some times to see how things are working when you can watchthe vars change as the script executes, and be able to see into DOM


objects
to see if they are null or assigned with ids and values as expected.

http://www.mandala.com/javascript/debug_javascript.html
Javascript Debugging with the MS Script Editor

Ciao,
Jeff




Jul 23 '05 #5

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

Similar topics

14
by: Timothy Madden | last post by:
Hello I have a linked list of object of a class. I thought it would be nice to have the destructor delete the whole list when I delete just the first element. I don't want to recursivly destroy...
5
by: phil_gg04 | last post by:
Dear Javascript Experts, Opera seems to have different ideas about the visibility of Javascript functions than other browsers. For example, if I have this code: if (1==2) { function...
14
by: subramanian100in | last post by:
In the following link, http://www.c-faq.com/malloc/retaggr.html The following ANSWER is given to a question(comp.lang.c FAQ list · Question 7.5a) : Whenever a function returns a pointer, make...
6
by: Anthony Smith | last post by:
I can call a class using "->", but it complains about the :: I see on the net where :: is used. Is there a good explanation on when to use one over the other or the differences? $help = new...
1
by: jman | last post by:
i've got an object and i'd like to recursively call a function within the class definition. (i've simplified the code ) function myclass() { this.loop = function(index) { // ..work
8
by: ais523 | last post by:
I've been doing this sort of thing, and I want to know if it's a sensible way to act (I think this is correct and portable, but want to make sure): int f(int a, void(*b)()) { static int x=0;...
4
by: Steve Hershoff | last post by:
Hi everyone, We have a javascript function we'd like to call from within a C# method in our code-behind file. The way it has worked historically is we'd call the method from a hyperlink, like...
1
by: George2 | last post by:
Hello everyone, Such code segment is used to check whether function call or exception- handling mechanism runs out of memory first (written by Bjarne), void perverted() { try{
9
by: pereges | last post by:
Hello I need some ideas for designing a recursive function for my ray tracing program. The idea behind ray tracing is to follow the electromagnetic rays from the source, as they hit the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.