Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 24th, 2006, 9:28 AM   #1
paulmedic555
Newbie
 
paulmedic555's Avatar
 
Join Date: Jan 2005
Location: Greece
Posts: 18
Rep Power: 0 paulmedic555 is on a distinguished road
Send a message via MSN to paulmedic555
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?
paulmedic555 is offline   Reply With Quote
Old Nov 24th, 2006, 11:33 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Nov 24th, 2006, 12:10 PM   #3
paulmedic555
Newbie
 
paulmedic555's Avatar
 
Join Date: Jan 2005
Location: Greece
Posts: 18
Rep Power: 0 paulmedic555 is on a distinguished road
Send a message via MSN to paulmedic555
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
paulmedic555 is offline   Reply With Quote
Old Nov 25th, 2006, 1:59 AM   #4
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
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.
bl00dninja is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:17 PM.

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