![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
|
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><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> |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Newbie
|
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><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> |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
it wasn't stupid...you fixed your problem.
oftentimes all you need is a fresh perspective. good luck!
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Simple blackjack script problem. Need help. | jokr004 | C++ | 6 | Feb 10th, 2006 11:44 AM |
| A simple script isn't working correctly | scuzzman | Perl | 3 | Dec 23rd, 2005 6:42 AM |
| A simple perl script | satimis | Perl | 3 | Aug 15th, 2005 9:31 AM |
| A simple script to execute a command package | satimis | Bash / Shell Scripting | 3 | Aug 12th, 2005 11:28 PM |
| Simple menu script | trufla | Bash / Shell Scripting | 2 | Apr 4th, 2005 10:17 AM |