Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 18th, 2005, 09:48 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
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
Reply With Quote
  #2 (permalink)  
Old October 18th, 2005, 10:32 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
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

Reply With Quote
  #3 (permalink)  
Old October 19th, 2005, 11:34 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
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
Reply With Quote
  #4 (permalink)  
Old October 20th, 2005, 04:54 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
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

Reply With Quote
  #5 (permalink)  
Old October 20th, 2005, 05:20 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
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
Reply With Quote
  #6 (permalink)  
Old October 20th, 2005, 05:25 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
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
Reply With Quote
  #7 (permalink)  
Old October 20th, 2005, 05:39 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
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
Reply With Quote
  #8 (permalink)  
Old October 20th, 2005, 05:42 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:34 PM.


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