cupofjava
07-12-2005, 01:21 PM
Thanks very much for your help its working now :)
|
||||
Alphabet Check Javascript Problemcupofjava 07-12-2005, 01:21 PM Thanks very much for your help its working now :) glenngv 07-12-2005, 01:35 PM Conditional operator is == and not =. glenngv 07-12-2005, 02:10 PM You're welcome. :) But why did you overwrite your original post? Others who might have similar problem can use it as a reference. cupofjava 07-12-2005, 06:23 PM 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> nikkiH 07-12-2005, 06:41 PM 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/kaelisSpace/useful_jsValidation.html function isAlpha(val) { // True if val is a single alphabetic character. var re = /^([a-zA-Z])$/; return (re.test(val)); } cupofjava 07-12-2005, 06:53 PM 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? Willy Duitt 07-12-2005, 08:59 PM http://www.webdeveloper.com/forum/showthread.php?t=72612 cupofjava 07-12-2005, 09:04 PM 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 Willy Duitt 07-12-2005, 09:11 PM 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... 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 cupofjava 07-12-2005, 09:13 PM Oh right of course I did DUH! Sorry bout that... Willy Duitt 07-12-2005, 09:17 PM 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 nikkiH 07-13-2005, 01:15 AM A full solution: <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> |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum