Submit Your Article Forum Rules

Results 1 to 6 of 6

Thread: Simple maths query

  1. #1
    Senior Member
    Join Date
    Jun 2004
    Posts
    125

    Simple maths query

    Hi can someone please help me with this query?

    I am using Dreamweaver. I have an ASP/VBScript page adding information from a form to a database.

    I have two fields which both a drop down box containing 5 different selections numbered 1 to 5. The third field contains a score which is the first field multiplied by the second field.

    Can someone help me with the code to achieve this please.

    kind regards
    emma gale

  2. #2
    WebProWorld MVP brian.mark's Avatar
    Join Date
    Jul 2004
    Posts
    2,709

    Not to complicate it more...

    Not to complicate it more, but we're going to add another language. JavaScript to be more precise.

    Code:
    <Script Language="JavaScript">
    <!--
    function dothemath()
    {
    	calcform.answer.value=calcform.number1.value * calcform.number2.value;
    }
    //-->
    </Script>
    
    <form name="calcform">
    Number 1: <select name="number1" onChange="dothemath();">
    	<option value="1">1
    	<option value="2">2
    	<option value="3">3
    	<option value="4">4
    	<option value="5">5
    	</select>
    
    Number 2: <select name="number2" onChange="dothemath();">
    	<option value="1">1
    	<option value="2">2
    	<option value="3">3
    	<option value="4">4
    	<option value="5">5
    	</select>
    
    Score: <input type=text name="answer" value="1" size=3>
    </form>
    You could also make the score a hidden field to just pass it when you do your form post. It's not pretty code... that part is up to you.

    Brian.
    ToolBarn.com, an Internet Retailer Top 500 and Inc. 500 Company | Tool Parts | Pet Supplies

  3. #3
    Senior Member
    Join Date
    Jun 2004
    Posts
    125
    Thank you so so much! It works a treat!

    I have got it writing to the input box, hidden the field and writing it to the page!

    Wonderful stuff!

    Thanks again
    emma

  4. #4
    Senior Member
    Join Date
    Jun 2004
    Posts
    125

    Thanks

    Thats is great it works a treat.

    I only have one small query with it.

    I can make the field hidden and write the original variable to the form but this variable doesnt change at all when the calculation has taken place. Im not too good with javascript but managed to get this far:

    <td width="12%" valign="top" class="entertext">
    <input type="textfield" name="answer" value="0" size=3>
    <script language="javascript" type="text/javascript">
    document.write(form1.answer.value);
    </script>
    </td>

    All it does is put the original value of 0.

    With kind regards
    emma

  5. #5
    WebProWorld MVP brian.mark's Avatar
    Join Date
    Jul 2004
    Posts
    2,709

    I think your field type was a problem.

    I think you needed to use hidden instead of textfield.

    Code:
    <Script Language="JavaScript">
    <!--
    function dothemath()
    {
       calcform.answer.value=calcform.number1.value * calcform.number2.value;
    }
    //-->
    </Script>
    
    <form name="calcform" action="test.html" method=get>
    Number 1: <select name="number1" onChange="dothemath();">
       <option value="1">1
       <option value="2">2
       <option value="3">3
       <option value="4">4
       <option value="5">5
       </select>
    
    Number 2: <select name="number2" onChange="dothemath();">
       <option value="1">1
       <option value="2">2
       <option value="3">3
       <option value="4">4
       <option value="5">5
       </select>
    
    <input type=hidden name="answer" value="1" size=3>
    <input type=submit>
    </form>
    I loaded this on our server and tested it. http://www.toolbarn.com/test.html. When you submit, it'll show the answer in the URL string.

    Brian.
    ToolBarn.com, an Internet Retailer Top 500 and Inc. 500 Company | Tool Parts | Pet Supplies

  6. #6
    Senior Member
    Join Date
    Jun 2004
    Posts
    125
    Thank you for your help - that sorted that problem out nicely.

    kind regards
    Emma

Similar Threads

  1. MySQL query works on CLI or Query Browser but NOT in PHP
    By CraigB in forum Database Discussion Forum
    Replies: 4
    Last Post: 09-28-2006, 10:39 AM
  2. Google Fuzzy maths
    By TrafficProducer in forum Google Discussion Forum
    Replies: 2
    Last Post: 05-16-2006, 03:29 PM
  3. CSS query
    By EmmaGale in forum Web Programming Discussion Forum
    Replies: 0
    Last Post: 03-05-2006, 07:09 PM
  4. CMS Query
    By syberboy in forum Web Programming Discussion Forum
    Replies: 0
    Last Post: 12-22-2005, 07:23 PM
  5. some simple MOD rewrite help - like its ever simple
    By freehits in forum Web Programming Discussion Forum
    Replies: 1
    Last Post: 05-18-2005, 12:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •