Closed Thread Icon

Topic awaiting preservation: Calling a function from within a function? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8233" title="Pages that link to Topic awaiting preservation: Calling a function from within a function? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Calling a function from within a function? <span class="small">(Page 1 of 1)</span>\

 
Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 07-09-2002 20:44

Ok - I think I've just been in the sun a little too long....

I have this function...

switch(article_author){
case "cardenas" :
enter_data.author_name.value = "Edward L. Cardenas / The Detroit News";
enter_data.author_email.value = "ecardenas@detnews.com";
enter_data.author_phone.value = "(586) 468-0529";
mycopyright(3);
break
case "cook" :
enter_data.author_name.value = "Jameson Cook, Macomb Daily Staff Writer";
enter_data.author_email.value = "";
enter_data.author_phone.value = "";
mycopyright(1);
alert("1");
break
default :
enter_data.author_name.value = "";
enter_data.author_email.value = "";
enter_data.author_phone.value = "";
}
}

The problem is that the mycopyright() function isn't being called. If the value being submitted to the function is "cook", everything happens (that should), including the ALERT("1");, except for the calling of mycopyright(1);. No errors, nothing. So I'm guessing the answer is staring me straight in the face, but I don't see it.

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 07-09-2002 20:53

I guess that you have some kind of error in mycopyright() function which causes it not to run. Can you show us complete page (switch statement that you posted above is correct)...


Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 07-09-2002 21:02

Well, I can't show the whole page - it's HUGE (and secured). But here is some more:

<B>function mycopyright(copyright){
if (copyright < 1

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 07-09-2002 21:13

Okay, I think I found the issue.

mycopyright(1); doesn't work, but
mycopyright("1"); does.

I noticed that the SWITCH statement was using quoted values to execute....



[This message has been edited by Pugzly (edited 07-09-2002).]

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 07-09-2002 21:55

I suspect that since you're passing numbers, and using

case "1":
...

with strings, that's why it doesn't work. So perhaps if you changed all the values after the word "case" to numbers, it would work:

case 1:
...

The data types (strings vs numbers) probably have to match up.

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 07-09-2002 22:16

Yeah, that's what it was. I just called the function with a quoted value, and PRESTO! it worked. And actually, it WAS working - it was taking the default value of the switch, which was leaving the form fields blank. That's why I wasn't getting an error.....

I swear - syntax issues are going to be the death of me....

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 07-09-2002 23:37

If I were you, instead of calling it with a string, I'd change the cases to numbers. Because if it's >1 or < 5, it'll be converted to a number anyway, and then you might have trouble.

Hugh
Paranoid (IV) Inmate

From: Dublin, Ireland
Insane since: Jul 2000

posted posted 07-12-2002 21:42

thats kinda weird. In the good few years Ive been using JS , I never knew you could use switch !
And even weirder.. Ive been in a few situations where I could have used it and thought to myself "no thats only in C" he he, now Im all the wiser.

P.s I noticed the string thing too, that has to be most common mistake (no offence intended, even amazing people like ourselves make mistakes ) thats usually the first thing I look out for.

« BackwardsOnwards »

Show Forum Drop Down Menu