Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   JavaScript and Client-Side Browser Scripting (http://www.programmingforums.org/forum23.html)
-   -   simple multiply script (http://www.programmingforums.org/showthread.php?t=11987)

paulmedic555 Nov 24th, 2006 10:28 AM

simple multiply script
 
Hi all our teacher gave us this simple script that when someone gives two numbers in two forms then it will multiply their contents and print the result in an another form after he click one button.Here is the code:
:

<script language="javascript">
function convert (form)
{
  if ((form.first.value == "")
      (form.second.value =="")) 
      return;
  form.result.value=form.first.value * form.second.value;   

</script>

and
:

<form method="post">
Give first number:<input type="text" name="first" value=0 onchange=convert(this.form)>
<p>Give second number:<input type="text" name="second" value=0 onchange=convert(this.form)>
<p><input type="button" name="calculate" value="calculate" onclick=convert(this.form)>
<p>Result:<input type="text" name="result" value="not calculated" ><br>
</form>

I only tried in firefox and it didn't work.Any ideas?

DaWei Nov 24th, 2006 12:33 PM

You didn't copy it correctly. You're missing a logical operator between the two expressions in the "if". I didn't look beyond that. You could well get into conversion problems, auto conversion or not.

paulmedic555 Nov 24th, 2006 1:10 PM

Yes i didn't copy it correctly.I was missing a logical "or" operator between the expressions of "if".Now it works :
:

<script language="javascript">
function convert (form)
{
  if ((form.first.value == "") ||
      (form.second.value ==""))
      return;
  form.result.value=form.first.value * form.second.value;   

</script>

and
:

<form method="post" > 
Give first number:<input type="text" name="first" value=0 onchange=convert(this.form)>
<p>Give second number:<input type="text" name="second" value=0 onchange=convert(this.form)></p>
<p><input type="button" name="calculate" value="calculate" onclick=convert(this.form)></p>
<p>Result:<input type="text" name="result" value="not calculated" ></p><br>
</form>

Sorry for the stupid post

bl00dninja Nov 25th, 2006 2:59 AM

it wasn't stupid...you fixed your problem.

oftentimes all you need is a fresh perspective.

good luck!


All times are GMT -5. The time now is 1:34 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC