Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 18th, 2005, 09:48 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default check if first char is a letter

Code:
seat_zelle.innerHTML = "<input type=text id=specify"+s+" name=specify"+s+" class=selects size=5 onKeyUp='this.value=this.value.toUpperCase();'/>";
I am building this textbox in innerHTML, how can i put a condition on it so that it detects what is inputted so that if the first char that is entered
is a LETTER then it alerts the user?

Picco

www.crmpicco.co.uk
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
 
Old October 18th, 2005, 10:32 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

onKeyUp='this.value=this.value.toUpperCase();' if(/^[a-z]/i.test(this.value)){alert(\"first char is a letter\")};'

HTH,

Chris

 
Old October 19th, 2005, 11:34 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

thanks for that chris, have you got a function that will check if AT LEAST ONE character in a textbox is a letter?

www.crmpicco.co.uk
 
Old October 20th, 2005, 04:54 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Sure...
Code:
onkeyup="if(/^.*[a-z].*/i.test(this.value)){alert('at least one letter')};"
If you're going to be doing a lot of string comparisons, I'd highly recommend a look at regular expressions.

Cheers,

Chris

 
Old October 20th, 2005, 05:20 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

thanks again chris, trying to think of a function name. ive got function IsNumeric(sText,id) to check for numeric fields IsAlpha is A-Z AND 0-9 got a name for letters only (A-Z) :-) LOL

www.crmpicco.co.uk
 
Old October 20th, 2005, 05:25 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

Code:
                seat_zelle.innerHTML = "<input type='text' id='specify"+s+"' name='specify"+s+"' "+
                                       "title='Insert Seat Number for Pax: "+ passagier + " " + passNo + " / Segment "+ parseFloat(s+1) +"' "+
                                       "class='selects' size='5' onBlur='containsLetter(this.value,this.id); concatSeats(this.value,"+passNo+",this.id,"+pass+");' onKeyUp='this.value=this.value.toUpperCase(); return IsNumeric(this.value,this.id);' />";

function containsLetter(sText,id)
{
    if(/^.*[A-Z].*/i.test(this.value))
    {
        alert("The Seat must contain at least one letter");
        return false;
    }
}
Can't seem to get it working with this code above???

www.crmpicco.co.uk
 
Old October 20th, 2005, 05:39 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

Code:
                seat_zelle.innerHTML = "<input type='text' id='specify"+s+"' name='specify"+s+"' "+
                                       "title='Insert Seat Number for Pax: "+ passagier + " " + passNo + " / Segment "+ parseFloat(s+1) +"' "+
                                       "class='selects' size='5' onBlur='if(!/^.*[a-z].*/i.test(this.value)){alert('The Seat must contain a letter')}; concatSeats(this.value,"+passNo+",this.id,"+pass+");' "+
                                       "onKeyUp='this.value=this.value.toUpperCase(); return IsNumeric(this.value,this.id);' />";
Getting an syntax error with this code.
Doesnt seem to like anything inside quotes for the alert. Can i send it to a fucntion to check then alert?

www.crmpicco.co.uk
 
Old October 20th, 2005, 05:42 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

Code:
                seat_zelle.innerHTML = "<input type='text' id='specify"+s+"' name='specify"+s+"' "+
                                       "title='Insert Seat Number for Pax: "+ passagier + " " + passNo + " / Segment "+ parseFloat(s+1) +"' "+
                                       "class='selects' size='5' onBlur='if(!/^.*[a-z].*/i.test(this.value)){alertUser();}; concatSeats(this.value,"+passNo+",this.id,"+pass+");' "+
                                       "onKeyUp='this.value=this.value.toUpperCase(); return IsNumeric(this.value,this.id);' />";
function alertUser()
{
    alert("The Seat must contain a letter for the row identifer");
    return false;
}
this works, but can i do the validation and the alert in one function?

thanks.

picco

www.crmpicco.co.uk





Similar Threads
Thread Thread Starter Forum Replies Last Post
Letter replace in hangman. martoufmarty Javascript How-To 12 June 17th, 2008 12:30 AM
Big challenge here! How to convert char* to char^? samiswt Visual C++ 2005 1 November 30th, 2007 09:09 PM
check/letter box ,submit button grazian7 ASP.NET 2.0 Professional 0 November 30th, 2007 11:15 AM
Invalid conversion from 'char*' to 'char' deuxmio C++ Programming 3 December 8th, 2006 07:56 AM
search first letter keyvanjan Classic ASP Basics 2 May 17th, 2006 01:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.