Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to call another function?

21 views
Skip to first unread message

parmenides

unread,
Jul 3, 2017, 2:37:15 AM7/3/17
to
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.



Ben Bacarisse

unread,
Jul 3, 2017, 7:31:21 AM7/3/17
to
parmenides <xparm...@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.

JJ

unread,
Jul 3, 2017, 11:18:31 PM7/3/17
to
Name conflict.
No return value for onsubmit.
0 new messages