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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Oct 2003
    Location
    NSW, Australia
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks anyway - question answered

    .
    Last edited by Nicole; 10-09-2003 at 02:26 PM.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts

    Welcome to the forum!

    post the codes here or attach it if it's too long

  • #3
    New to the CF scene
    Join Date
    Oct 2003
    Location
    NSW, Australia
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here it is
    Last edited by Nicole; 10-09-2003 at 02:32 PM.

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Ok, here's your code. Before that, beware... there were a lot of mistakes within your code, take care for the future... No offence, please

    Take care, your brackets were incorrect. If use local variables var, maybe is better to put them inside the function. You forgot to give a name to a checkbox. If you nedd a veryfing condition, use return condition before calling a function, and the responsereturn true or return false for stop or continue the code. Otherwise, evem you have an alert, the function will go till the end, despite your condition...

    And a question... do you really need a separate form for each form object? I think a single form which will include all will do the job...

    And, with some definite and few exceptions, the code must be insert in HEAD not in BODY. The code will work in both cases, but is a better position in head, becouse this way you are sure that it will be loaded, as the head is loaded first. I hope I was not too
    pedantic...

    Now:
    PHP Code:
    <html>
    <
    head>
    <
    title>Wally World Ticket Price Calculator</title>
    <
    script language="javascript">
    function 
    calculateCost(){
    var 
    AO 10;         
    var AS = 
    20;        
    var 
    ASR 30;

    if (
    document.tickettypeForm.tickettype.selectedIndex == 1)
    {
    ticket=AO;}
    else if (
    document.tickettypeForm.tickettype.selectedIndex == 2)
    {
    ticket=AS;}
    else if (
    document.tickettypeForm.tickettype.selectedIndex == 3)
    {
    ticket=ASR;}
    else if (
    document.tickettypeForm.tickettype.selectedIndex == 0)
    {
    alert("You need to select a ticket type first.");return false}
    if (
    document.guesttypeForm.guesttype[0].checked)
    {
    guest=2;}              
    else if (
    document.guesttypeForm.guesttype[1].checked)
    {
    guest=1.5;}
    else if (
    document.guesttypeForm.guesttype[2].checked)
    {
    guest=1;}
    else
    {
    alert("You need to select a guest type first.");return false}
    cost=ticket*guest;
    if (
    document.checkboxForm.checkbox.checked)
    {
    cost=ticket*guest*2;}
    alert("The cost of the ticket is $" cost);
    }
    </script>
    </head>

    <body>

    <h1>Wally World Ticket Price Calculator</h1>
    <br>
    Complete the form below to calculate the cost of your ticket.

    <form name="tickettypeForm">
    Ticket type:
    <select name="tickettype" size="1">
    <option></option>
    <option>Admission only</option>
    <option>Admission and all shows</option>
    <option>Admission, all shows and unlimited rides</option>
    </select>
    </form>

    <form name="checkboxForm">
    Click here if you would like a two-day ticket:
    <input type="checkbox" name="checkbox">
    </form>
    <br>

    <form name="guesttypeForm">
    Guest type:
    <br>
    <input type="radio" name="guesttype">Adult<br>
    <input type="radio" name="guesttype">Concession<br>
    <input type="radio" name="guesttype">Child (under 12)
    </form>
    <br>

    <form>
    <input type="button" onClick="return calculateCost()" value="Calculate">&nbsp;<input type="reset">
    </form>
    </body>
    </html> 
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    oops... I see now the reset don't work, as it refferes to a definite form, not to all. See now why is better (in case you don't need different forms, for sumbit reasons) to use a single form. Here is the correct code, with a small coorection either (make document.forms[0] a variable, as it repeats in code several times):

    PHP Code:
    <html>
    <
    head>
    <
    title>Wally World Ticket Price Calculator</title>
    <
    script language="javascript">
    function 
    calculateCost(){
    var 
    AO 10;         
    var AS = 
    20;        
    var 
    ASR 30;
    document.forms[0];
    if (
    d.tickettype.selectedIndex == 1)
    {
    ticket=AO;}
    else if (
    d.tickettype.selectedIndex == 2)
    {
    ticket=AS;}
    else if (
    d.tickettype.selectedIndex == 3)
    {
    ticket=ASR;}
    else if (
    d.tickettype.selectedIndex == 0)
    {
    alert("You need to select a ticket type first.");return false}
    if (
    d.guesttype[0].checked)
    {
    guest=2;}              
    else if (
    d.guesttype[1].checked)
    {
    guest=1.5;}
    else if (
    d.guesttype[2].checked)
    {
    guest=1;}
    else
    {
    alert("You need to select a guest type first.");return false}
    cost=ticket*guest;
    if (
    d.checkbox.checked)
    {
    cost=ticket*guest*2;}
    alert("The cost of the ticket is $" cost);
    }
    </script>
    </head>
    <body>
    <h1>Wally World Ticket Price Calculator</h1>
    <br>
    Complete the form below to calculate the cost of your ticket.
    <form>
    Ticket type:
    <select name="tickettype" size="1">
    <option></option>
    <option>Admission only</option>
    <option>Admission and all shows</option>
    <option>Admission, all shows and unlimited rides</option>
    </select>
      <br>
      <br>
      Click here if you would like a two-day ticket: 
      <input type="checkbox" name="checkbox">
    <br>
    <br>
      Guest type: <br>
    <input type="radio" name="guesttype">Adult<br>
    <input type="radio" name="guesttype">Concession<br>
    <input type="radio" name="guesttype">Child (under 12)
    <br>
    <br>
    <input type="button" onClick="return calculateCost()" value="Calculate">&nbsp;<input type="reset">
    </form>
    </body>
    </html> 
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #6
    New to the CF scene
    Join Date
    Oct 2003
    Location
    NSW, Australia
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Kor you are a genius
    Thank you thank you thank you

    I knew I had major mistakes, but now I can see where I went wrong.
    If you are ever in country NSW Australia I'll buy you a beer!!!

    This is a great site & I'll be definitely be back, hopefully helping someone else.

    Cheers Nicole

  • #7
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    TX for the beer, consider it already drunk (not me , the beer ) even I live in the opposite part of the Globe. I'll be glad to help you,as far as my knowledges let me, anytime.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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