Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: How to call another function? Date: Mon, 03 Jul 2017 12:31:11 +0100 Organization: A noiseless patient Spider Lines: 50 Message-ID: <87d19h7o5c.fsf@bsb.me.uk> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="7f9cbcc9ed94d0322ece7ddb3c642398"; logging-data="15089"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ET1Kclqw32xM9eA8L8dDNiH+3oqRKlW0=" Cancel-Lock: sha1:rHjUposxlnOcyVPHL7xjRNk3eH4= sha1:ak4sziubEgKES9cpPliOxP3oHK4= X-BSB-Auth: 1.f72392ea69f8286b4538.20170703123111BST.87d19h7o5c.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:33571 parmenides 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!) > > > Document > > > >
> >
> > > > 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? -- Ben.