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 2 of 2
  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    23
    Member #
    25361
    Hi,
    Please i have this code which is not working correctly,please can somebody help write it incorrect order for me.
    When i write it on a separate notepad then it works but when i write or combine them on a single notepad like what is here it do not work.
    Help me please,here is the code

    <html>
    <body>
    <script type="text/javascript">
    function calculate(){
    A=Number(document.frmone.txtfirstnumber.value)
    B=Number(document.frmone.txtsecondnumber.value)
    A=Number(A)
    B=Number(B)
    C=A+B
    document.frmone.txtthirdnumber.value=C

    if(Number(A) && Number(B)){
    A=Number(A)
    B=Number(B)
    C=A+B
    document.frmone.txtthirdnumber.value=C
    }
    else{
    alert("Enter a number in both boxes")
    }
    }

    // here is another subtraction code to calculate
    function calculate(){
    A=Number(document.frmone2.txtfirstnumber.value)
    B=Number(document.frmone2.txtsecondnumber.value)
    A=Number(A)
    B=Number(B)
    C=A-B
    document.frmone2.txtthirdnumber.value=C
    if(Number(A) && Number(B)){
    A=Number(A)
    B=Number(B)
    C=A-B
    document.frmone2.txtthirdnumber.value=C
    }
    else{
    alert("Enter a number in both boxes")
    }
    }


    // here is a palindrom code
    function palinChecker()
    {
    var string = document.palindrome.input.value;
    document.palindrome.palindrometext.value = reverseString(string);

    if (isPalindrome(string))
    {
    alert("That IS a palindrome.");
    }
    else
    {
    alert("That is NOT a palindrome.");
    }
    }
    <p>Here is palindrome checker code</p>
    function isPalindrome (inputString)
    {
    var reversedString = reverseString(inputString);
    return (reversedString==reverseString(reversedString));
    }

    function reverseString(stringToReverse)
    {
    stringToReverse = stringToReverse.toUpperCase();
    var reversedString="";
    var length= stringToReverse.length-1;
    var ch;
    for (var i=length; i>=0; i--)
    {
    ch = stringToReverse.charAt(i)
    if(ch >='A' && ch <='Z')
    {
    reversedString += ch;
    }
    }
    return reversedString;
    }
    </script>
    </head>

    <body>
    <form name=frmone>
    Value one: <input type=text name=txtfirstnumber size=5 value=""/>
    value two: <input type=text name=txtsecondnumber size=5 value=""/>
    Total:<input type=text name=txtthirdnumber size=5 value=""/>
    <input type="button" value="Add Numbers" onclick="calculate()"/>
    <p>this is a subtraction text field,just enter a number and get a result</p>

    <form name=frmone2>

    Value one: <input type=text name=txtfirstnumber size=5 value=""/>
    value two: <input type=text name=txtsecondnumber size=5 value=""/>
    Total:<input type=text name=txtthirdnumber size=5 value=""/>
    <input type="button" value="Subtract Numbers" onclick="calculate()"/>
    <p>Here is palindrome form filed</p>


    <form name="palindrome">
    <p>Enter phrase: <input type="text" name="input"><br>
    <input type="button" name="check" value="Check if palindrome" onclick="palinChecker();"><br>
    <input type="text" name="palindrometext" value=""></p>
    </form>
    </body>
    </html>

    Thank you.
    Clement Osei.

  2.  

  3. #2
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    You've got two functions with the same name. That won't work.

    Change one of your calculate function names.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)


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:43 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com