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


Groups > comp.lang.javascript > #17362

Re: New to javascript, please help

From Stefan Weiss <krewecherl@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: New to javascript, please help
Date 2012-11-27 14:44 +0100
Organization albasani.net
Message-ID <k92g3b$jgs$1@news.albasani.net> (permalink)
References <ce72955e-bce6-4b90-bba1-7398e884f41a@googlegroups.com>

Show all headers | View raw


On 2012-11-27 14:14, Christian van der Meij wrote:
> I am trying to learn javascript and in particular in conjunction
> with forms to make some calculations. I like browsing the web to
> find the information I need. However I am stuck right now.....
> can somebody point me in good direction to get this code working.

Next time, please tell us what you're trying to do and which part should
work differently.

The short answer in your case is that when you hit the submit button,
your form gets submitted. This will cause the page to be reloaded*. You
can prevent that by returning false in the onsubmit attribute:

  <form ... onsubmit="return false">

If you want your submit handler to execute as well, you can either use
something like this -

  <form ... onsubmit="CalcTas(); return false">

- or you can use the return value from the CalcTas() function:

      function CalcTas () {
          ...
          return false;
      }
  </script>
  <form ... onsubmit="return CalcTas()">

This will solve your immediate problem.
Now for some other things you should do:

*Always* validate your HTML before you go looking for JS errors. Your
document is not valid HTML 5; use http://validator.nu/ (for HTML 5) or
http://validator.w3.org/ (for all flavors) to check the document.

> 	tas = (ias * (1 + ((alt / 1000) *.02)));

You didn't declare the variable tas. This will make tas a global
variable. You can use tools like JsLint to find problems like this.

> 	return;
> 	}

This doesn't do anything, the function would return at that point anyway
(and the return value would be undefined, with or without the extra
'return' statement).


HTH,
stefan


*] Actually, a reload is just one of the things that could happen. Since
you left the action attribute of the form empty, the behavior is
unspecified. An empty action attribute is not valid in HTML.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

New to javascript, please help Christian van der Meij <chriscross1972@gmail.com> - 2012-11-27 05:14 -0800
  Re: New to javascript, please help Tim Streater <timstreater@greenbee.net> - 2012-11-27 13:30 +0000
    Re: New to javascript, please help Christian van der Meij <chriscross1972@gmail.com> - 2012-11-27 06:32 -0800
  Re: New to javascript, please help Stefan Weiss <krewecherl@gmail.com> - 2012-11-27 14:44 +0100
    Re: New to javascript, please help Christian van der Meij <chriscross1972@gmail.com> - 2012-11-27 06:40 -0800
      Re: New to javascript, please help "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2012-11-27 20:51 +0100

csiph-web