Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Functions causing me problems

    Hello everyone,

    I am very new to javascript and experimenting on my own. I believe that my functions are interferring with each other. If you have any ideas let me know and I will apply them. Till then I will keep on reading.

    Thank You,
    Eric

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
    <title>FISH CALCULATOR</title>
    <script language="javascript">

    function reset(){
    val1.value="";
    val2.value="";
    val3.value="";
    answer.value="";
    }
    function initialise(){
    CONCEPT=document.calc.concept.options[0]
    newportbay=document.calc.concept.options[1]
    stanfords=document.calc.concept.options[2]
    chophouse=document.calc.concept.options[3]
    citygrill=document.calc.concept.options[4]
    manzana=document.calc.concept.options[5]
    henrys=document.calc.concept.options[6]
    seafoodgrill=document.calc.concept.options[7]
    }
    function cost(){
    x =parseint(document.calc.val1.value)
    y =parseint(document.calc.val2.value)
    z =parseint(document.calc.val3.value)
    if (newportbay.selected)
    document.calc.answer.value=x+y+z
    if (standfords.selected)
    document.calc.answer.value=x+y+z
    if (chophouse.selected)
    document.calc.answer.value=x+y+z
    if (citygrill.selected)
    document.calc.answer.value=x+y+z
    if (manzana.selected)
    document.calc.answer.value=x+y+z
    if (henrys.selected)
    document.calc.answer.value=x+y+z
    if (seafoodgrill.selected)
    document.calc.answer.value=x+y+z
    }
    </script>

    </head>
    <body style="text-align: center; background-image: url(bgfish3gif_100.gif);">
    <span style="font-family: Tahoma"><span style="font-family: Baskerville Old Face"><strong>
    <span style="font-size: 36pt; text-decoration: underline">FISH CALCULATOR</span></strong><br />
    <br />
    <br />
    <strong>
    SALMON PLATE COST CALCULATOR</strong></span><br />
    </span>
    <br />
    <table border="2">
    <tr>
    <td align="center" style="width: 100px; height: 30px;" valign="middle">
    Select<br />
    <select name="concept" size=1>
    <option selected value="">CONCEPT
    <option value="newportbay">newportbay
    <option value="stanfords">stanfords
    <option value="chophouse">chophouse
    <option value="citygrill">citygrill
    <option value="manzana">manzana
    <option value="henrys">henrys
    <option value="seafoodgrill">seafoodgrill
    </select>
    </td>
    <td align="center" style="width: 100px; height: 30px;" valign="middle">
    Per LB Price<br />
    <input type="text" name="val1" size=10 id="Text1">
    </td>
    <td align="center" style="width: 100px; height: 30px;" valign="middle">
    Yield<br />
    <input type="text" name="val2" size=10 id="Text2">
    </td>
    <td align="center" style="width: 100px; height: 30px;" valign="middle">
    Menu Price<br />
    <input type="text" name="val3" size=10 id="Text3">
    </td>
    <td align="center" style="width: 100px; height: 30px" valign="middle">
    =
    Plate Cost<br />
    <input type="text" name="answer" size=10 id="Text4" contenteditable="false">
    </td>
    </tr>
    </table>
    <br />
    <input type="button" value="cost" size=10 onclick="cost()">
    <input type="reset" value="reset" size=10 onclick="reset()">
    <br />
    <br />
    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,505
    Thanks
    3
    Thanked 501 Times in 488 Posts
    Code:
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
    <title>FISH CALCULATOR</title>
    <script language="javascript">
    
    function reset(){
     var frm=document.calc;
     frm.val1.value="";
     frm.val2.value="";
     frm.val3.value="";
     frm.answer.value="";
    }
    
    
    function initialise(){
    }
    
    function cost(){
     var frm=document.calc;
     var x =parseInt(frm.val1.value)||0;
     var y =parseInt(frm.val2.value)||0;
     var z =parseInt(frm.val3.value)||0;
     if (frm.concept.value=='newportbay')
      frm.answer.value=x+y+z
     if (frm.concept.value=='standfords')
      frm.answer.value=x+y+z
     if (frm.concept.value=='chophouse')
      frm.answer.value=x+y+z
     if (frm.concept.value=='citygrill')
      frm.answer.value=x+y+z
     if (frm.concept.value=='manzana')
      frm.answer.value=x+y+z
     if (frm.concept.value=='henrys')
      frm.answer.value=x+y+z
     if (frm.concept.value=='seafoodgrill')
      frm.answer.value=x+y+z
    }
    
    </script>
    
    </head>
    <body style="text-align: center; background-image: url(bgfish3gif_100.gif);">
    <span style="font-family: Tahoma"><span style="font-family: Baskerville Old Face"><strong>
    <span style="font-size: 36pt; text-decoration: underline">FISH CALCULATOR</span></strong><br />
    <br />
    <br />
    <strong>
    SALMON PLATE COST CALCULATOR</strong></span><br />
    </span>
    <br />
    <form name="calc" >
    <table border="2">
     <tr>
      <td align="center" style="width: 100px; height: 30px;" valign="middle">
       Select<br />
       <select name="concept" size=1>
       <option selected value="">CONCEPT
       <option value="newportbay">newportbay
       <option value="stanfords">stanfords
       <option value="chophouse">chophouse
       <option value="citygrill">citygrill
       <option value="manzana">manzana
       <option value="henrys">henrys
       <option value="seafoodgrill">seafoodgrill
       </select>
      </td>
      <td align="center" style="width: 100px; height: 30px;" valign="middle">
       Per LB Price<br />
       <input type="text" name="val1" size=10 id="Text1">
      </td>
      <td align="center" style="width: 100px; height: 30px;" valign="middle">
       Yield<br />
       <input type="text" name="val2" size=10 id="Text2">
      </td>
      <td align="center" style="width: 100px; height: 30px;" valign="middle">
       Menu Price<br />
      <input type="text" name="val3" size=10 id="Text3">
      </td>
      <td align="center" style="width: 100px; height: 30px" valign="middle">
        =
       Plate Cost<br />
       <input type="text" name="answer" size=10 id="Text4" contenteditable="false">
      </td>
     </tr>
    </table>
    
    <br />
    <input type="button" value="cost" size=10 onclick="cost()">
    <input type="reset" value="reset" size=10 onclick="reset()">
    <br />
    <br />
    </form>
    </body>
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Still not working right!

    Thank you VW phillips for looking at my script. If you can give me some feedback as to what you saw wrong I will try and better learn from it. If you have any idea why it is still not working let me know.
    Thank You

  • #4
    Regular Coder
    Join Date
    Oct 2003
    Posts
    603
    Thanks
    2
    Thanked 1 Time in 1 Post
    first, you have no closing </option>s
    second, you did not have <form name="calc"></form> tags
    third, you waste a lot of space setting variables for option[#] and asking if it is ".selected".... i changed it up some and i tested it and it works.
    Code:
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
    <title>FISH CALCULATOR</title>
    <script language="javascript">
    
    function reset(){
    document.calc.reset();
    }
    
    function cost(){
    x =parseInt(document.calc.val1.value)
    y =parseInt(document.calc.val2.value)
    z =parseInt(document.calc.val3.value)
    var selection = document.calc.concept.value;
    if (selection=="")
    alert("Select a Concept");
    document.calc.concept.focus();
    if (selection=="newportbay")
    document.calc.answer.value=(x+y+z)
    if (selection=="standfords")
    document.calc.answer.value=(x+y+z)
    if (selection=="chophouse")
    document.calc.answer.value=(x+y+z)
    if (selection=="citygrill")
    document.calc.answer.value=(x+y+z)
    if (selection=="manzana")
    document.calc.answer.value=(x+y+z)
    if (selection=="henrys")
    document.calc.answer.value=(x+y+z) 
    if (selection=="seafoodgrill")
    document.calc.answer.value=(x+y+z)
    } 
    </script>
    
    </head>
    <body style="text-align: center; background-image: url(bgfish3gif_100.gif);">
    <form name="calc">
    <span style="font-family: Tahoma"><span style="font-family: Baskerville Old Face"><strong>
    <span style="font-size: 36pt; text-decoration: underline">FISH CALCULATOR</span></strong><br />
    <br />
    <br />
    <strong>
    SALMON PLATE COST CALCULATOR</strong></span><br />
    </span>
    <br />
    <table border="2">
    <tr>
    <td align="center" style="width: 100px; height: 30px;" valign="middle">
    Select<br />
    <select name="concept" size=1>
    <option selected value="">CONCEPT</option>
    <option value="newportbay">newportbay</option>
    <option value="stanfords">stanfords</option>
    <option value="chophouse">chophouse</option>
    <option value="citygrill">citygrill</option>
    <option value="manzana">manzana</option>
    <option value="henrys">henrys</option>
    <option value="seafoodgrill">seafoodgrill</option>
    </select>
    </td>
    <td align="center" style="width: 100px; height: 30px;" valign="middle">
    Per LB Price<br />
    <input type="text" name="val1" size=10 id="Text1">
    </td>
    <td align="center" style="width: 100px; height: 30px;" valign="middle">
    Yield<br />
    <input type="text" name="val2" size=10 id="Text2">
    </td>
    <td align="center" style="width: 100px; height: 30px;" valign="middle">
    Menu Price<br />
    <input type="text" name="val3" size=10 id="Text3">
    </td>
    <td align="center" style="width: 100px; height: 30px" valign="middle">
    =
    Plate Cost<br />
    <input type="text" name="answer" size=10 id="Text4" contenteditable="false">
    </td>
    </tr>
    </table>
    <br />
    <input type="button" value="cost" size=10 onclick="cost()">
    <input type="reset" value="reset" size=10 onclick="reset()">
    <br />
    <br />
    </form>
    </body>
    </html>
    Last edited by boeing747fp; 08-01-2006 at 08:37 PM.

  • #5
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,505
    Thanks
    3
    Thanked 501 Times in 488 Posts
    you can give me some feedback as to what you saw wron
    best way to learn is if you study the script I posted, note also the reduction in code.
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/


  •  

    Posting Permissions

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