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 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Alphabet Check Javascript Problem

    Thanks very much for your help its working now
    Last edited by cupofjava; 07-12-2005 at 02:41 PM.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Conditional operator is == and not =.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    You're welcome.
    But why did you overwrite your original post? Others who might have similar problem can use it as a reference.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry for that, it was a mistake.

    I am going to post it again now. Problem I am having at the moment is that no matter whatever I enter it gives out same "false" answer any ideas??

    <html>
    <head>
    <title> question </title>

    <script
    language="JavaScript"
    type="text/javascript">



    var someInput;
    someInput = window.prompt('Please enter a single character ','');



    var theAnswer;

    function isInAlphabet (someInput) {



    if ((someInput == 'A') || (someInput == 'z'))

    theAnswer = true;


    } else {

    theAnswer = false;
    }

    return theAnswer;
    }

    var aResult;


    aResult = isInAlphabet();
    {

    document.open();
    document.write('The answer to whether ' + someInput + ' is in the alphabet is ' + theAnswer);
    document.close();
    }


    </script>
    </head>

    <body>

    </body>
    </html>
    Last edited by cupofjava; 07-12-2005 at 07:25 PM.

  • #5
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    No, you've got that all wrong. You're only checking for capital A and lower-case z.
    Try my isAlpha function, modified to accept only one letter.
    http://www.ipwebdesign.net/kaelisSpa...alidation.html
    Code:
    function isAlpha(val)
       {
       // True if val is a single alphabetic character.
       var re = /^([a-zA-Z])$/;
       return (re.test(val));
       }

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #6
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi thanks for your reply...

    I'm afraid that's a little bit beyond my talents at the moment!! I understand what the function is trying to do, in that it would only allow alpha characters but beyond that it means nothing to me and I can't get it to work..

    Anything a bit simpler?

  • #7
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #8
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Both of those posts were mine...I'm still looking for help! Thanks to all those who have replied i'm still working on it

  • #9
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Unfortunetly you removed your first post that showed what your original question was... However, a look at the question on the other thread I linked too, shows that all you need is isNaN...

    Quote Originally Posted by cupofjava
    Hello

    I am trying to complete the following code so that whenever I input character it can tell me whether or not it is a letter of the alphabet.

    However every time I input anything it comes up as false and I was told this might be because of my if statement as it seems to only be searching for the specific letters I have entered in the statement. I am a real beginner so any advice you can offer would have to be pretty clear and simple to be of use.

    I would be really grateful for any replies and thank you in advance:

    <html>
    <head>
    <title>question</title>

    <script
    language="JavaScript"
    type="text/javascript">




    var someInput; // declared variable
    someInput = window.prompt('Please enter a single character ',''); // window prompt



    var theAnswer;


    function isInAlphabet (someInput) {




    if ((someInput == 'A') || (someInput == 'z')) {

    theAnswer = true;


    } else {

    theAnswer = false;
    }

    return theAnswer;
    }

    var aResult;


    aResult = isInAlphabet();
    {

    document.open();
    document.write('The answer to whether ' + someInput + ' is in the alphabet is ' + theAnswer);
    document.close();
    }


    </script>
    </head>

    <body>

    </body>
    </html>

    Although, nikkiH's solution would work as well...

    .....Willy
    Last edited by Willy Duitt; 07-12-2005 at 10:14 PM.

  • #10
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oh right of course I did DUH!

    Sorry bout that...

  • #11
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by cupofjava
    Oh right of course I did DUH!

    Sorry bout that...
    Please update any other threads you may have started to indicate that a solution has been found - and what it was - or a link back here...

    Thank You;
    .....Willy

  • #12
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    A full solution:

    Code:
    <HTML>
    <HEAD>
    <TITLE> New Document </TITLE>
    </HEAD>
    
    <BODY>
    <script type="text/javascript">
    function isAlpha(val)
       {
       // True if val is a single alphabetic character.
       var re = /^([a-zA-Z])$/;
       return (re.test(val));
       }
    var someInput;
    someInput = window.prompt('Please enter a single character ','');
    
    document.write('The answer to whether ' + someInput + ' is in the alphabet is ' + isAlpha(someInput)); 
    </script>
    
    </BODY>
    </HTML>

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

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