Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    Aug 2007
    Posts
    2
    Member #
    15715
    I'm having an issue with updating this form. No matter what I do, javascript keeps returning that the 3rd condition in the function is true and spits out "IBM $1250". I have no idea why its doing this. I've changed it to all if statements and it works properly, why won't it work with the else/if?

    HTML Code:
    <script language="javascript" type="text/javascript">
    
    var compCosts = new Array();
    compCosts[1] = 1000;
    compCosts[2] = 500;
    compCosts[3] = 1250;
    
    
    function up_dater()
    {
    
        var orderDetails = "";    
    
        formElement = document.form1.processor;
        if (formElement[0].checked == true)
        {
            orderDetails = "Intel : $" + compCosts[formElement[0].value];
        }    
        else if (formElement[1].checked == true)
        {
            orderDetails = "AMD : $" + compCosts[formElement[1].value];
        }
        else (formElement[2].checked == true)
        {
            orderDetails = "IBM : $" + compCosts[formElement[2].value];
        }
    
        document.form1.txtorder.value = orderDetails;    
        
    
    }
    
    </script>
    </head>
    <body>
    
    <form name=form1>
    Choose a Processor<br />
           <input type="radio" name=processor value="1" />Intel<br />
           <input type="radio" name=processor value="2" />AMD<br />
           <input type="radio" checked name=processor value="3" />IBM<br /><br />
        
            <input type="button" name="updater" value="Update Price" onclick="up_dater()" /><br />
            <textarea name="txtorder" cols="30" rows="20" id="txtorder"></textarea>
    
    
    </form>

  2.  

  3. #2
    Junior Member
    Join Date
    Aug 2007
    Posts
    2
    Member #
    15715
    Ok. Figured it out. It was the last else statement.

  4. #3
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    Right, on the closing "catch all" else statement, you can't have a condition. Good catch.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:30 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com