Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #33570 > unrolled thread

How to call another function?

Started byparmenides <xparmenides@yahoo.com>
First post2017-07-03 14:37 +0800
Last post2017-07-04 10:18 +0700
Articles 3 — 3 participants

Back to article view | Back to comp.lang.javascript


Contents

  How to call another function? parmenides <xparmenides@yahoo.com> - 2017-07-03 14:37 +0800
    Re: How to call another function? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-07-03 12:31 +0100
    Re: How to call another function? JJ <jj4public@vfemail.net> - 2017-07-04 10:18 +0700

#33570 — How to call another function?

Fromparmenides <xparmenides@yahoo.com>
Date2017-07-03 14:37 +0800
SubjectHow to call another function?
Message-ID<ojcomg$16ad$1@gioia.aioe.org>
Hi all,
    I want to call a function from another funciton in the same js file. 
For example, in hello.js two functions are defined as follow:

// hello.js
function hello() {
	alert("hello");
}

function submit() {
	hello();
	return true;
}

Then, the submit() function is called in hello.html:
<--! hello.html -->
<html>
<head>
     <title>Document</title>
	<script src="hello.js"> </script>
</head>
<body>
	<form onsubmit="submit()">
		<input type="submit" value="submit" />
	</form>
</body>
</html>

But, the message box doesn't pop up as expected. If the onsubmit is 
replaced as
         onsubmit="hello()"
the message box can pop up. It seeems that a function can not call 
another function. Is it correct? How can I deal with the problem? Thanks.


[toc] | [next] | [standalone]


#33571

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2017-07-03 12:31 +0100
Message-ID<87d19h7o5c.fsf@bsb.me.uk>
In reply to#33570
parmenides <xparmenides@yahoo.com> writes:

> I want to call a function from another funciton in the same js
> file. For example, in hello.js two functions are defined as follow:
>
> // hello.js
> function hello() {
> 	alert("hello");
> }
>
> function submit() {
> 	hello();
> 	return true;
> }
>
> Then, the submit() function is called in hello.html:
> <--! hello.html -->

(The document should start with a doctype, not a comment!)

> <html>
> <head>
>     <title>Document</title>
> 	<script src="hello.js"> </script>
> </head>
> <body>
> 	<form onsubmit="submit()">
> 		<input type="submit" value="submit" />
> 	</form>
> </body>
> </html>
>
> But, the message box doesn't pop up as expected. If the onsubmit is
> replaced as
>         onsubmit="hello()"
> the message box can pop up. It seeems that a function can not call
> another function. Is it correct?

Obviously not!  I'm sure you don't really think that a function can't
call another so something else must be happening.  Try this experiment:
rename your submit function submitX in both places and see what happens.
What can you conclude anything from that experiment?

I know I could simply tell you what's happening (and I will if you
want) but surely it's better to learn how to think about these sorts of
thing?

<snip>
-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#33573

FromJJ <jj4public@vfemail.net>
Date2017-07-04 10:18 +0700
Message-ID<136gc3s4ebjbn.5kqsog6xvwtp.dlg@40tude.net>
In reply to#33570
On Mon, 3 Jul 2017 14:37:04 +0800, parmenides wrote:

> Hi all,
>     I want to call a function from another funciton in the same js file. 
> For example, in hello.js two functions are defined as follow:
> 
> // hello.js
> function hello() {
> 	alert("hello");
> }
> 
> function submit() {
> 	hello();
> 	return true;
> }
> 
> Then, the submit() function is called in hello.html:
> <--! hello.html -->
> <html>
> <head>
>      <title>Document</title>
> 	<script src="hello.js"> </script>
> </head>
> <body>
> 	<form onsubmit="submit()">
> 		<input type="submit" value="submit" />
> 	</form>
> </body>
> </html>
> 
> But, the message box doesn't pop up as expected. If the onsubmit is 
> replaced as
>          onsubmit="hello()"
> the message box can pop up. It seeems that a function can not call 
> another function. Is it correct? How can I deal with the problem? Thanks.

Name conflict.
No return value for onsubmit.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web