Membership is FREE, giving all registered users unlimited access to every Acorn Domains feature, resource, and tool! Optional membership upgrades unlock exclusive benefits like profile signatures with links, banner placements, appearances in the weekly newsletter, and much more - customized to your membership level!

javascript check form

Status
Not open for further replies.
Joined
Mar 14, 2007
Posts
396
Reaction score
2
I've got a bit of javascript to to check a field in a form on my web page.

It's a competition so I need to make sure the visitor types it in correctly.

the javascript to check the 'answer' field is

Code:
 if (form.answer.value != "brabantia") {	
    alert( "oops! try again?" );
    form.answer.focus();	
    return false ;
  }
  return true ;
}

but this is case sensitive.

I'd like to add some kind of other check for "Brabantia" too.

The javascript needs to return true whether the visitor enters 'brabantia' or 'Brabantia'

Any help?

Phil
 
PHP:
if (form.answer.value != "brabantia" && form.answer.value != "Brabantia") {	
    alert( "oops! try again?" );
    form.answer.focus();	
    return false ;
  }
  return true ;
}

Just modifying the if condition to check for both...

Probably I would use match() http://www.w3schools.com/jsref/jsref_match.asp with a case-insensitve regular expression.
 
Thanks JDubya

I haven't tried that yet but I did solve the problem

Instead of the javascript checker checking for lower and upper case I simply converted any uppercase to lower first in the html form on the page.

I used...

Code:
onChange="javascript:this.value=this.value.toLowerCase();"
 
PHP:
if (form.answer.value != "brabantia" && form.answer.value != "Brabantia") {	
    alert( "oops! try again?" );
    form.answer.focus();	
    return false ;
  }
  return true ;
}

Thanks for this it works fine.

Another bit of useful code snippet to add to my library.

Cheers
 
Status
Not open for further replies.

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Members online

Premium Members

Acorn Domains Merch
MariaBuy Marketplace

New Threads

Our Mods' Businesses

Laskos
*the exceptional businesses of our esteemed moderators
General chit-chat
Help Users
  • No one is chatting at the moment.
  • D AcornBot:
    DarkSky has left the room.
  • ukbackorder AcornBot:
    ukbackorder has left the room.
  • T AcornBot:
    ttek has left the room.
  • Admin @ Admin:
    Hello. So, do anyone happen to know anything about Whois and how it can be accessed?
  • BrandFlu AcornBot:
    BrandFlu has joined the room.
  • BrandFlu AcornBot:
    BrandFlu has left the room.
  • Helmuts @ Helmuts:
    Admin said:
    Hello. So, do anyone happen to know anything about Whois and how it can be accessed?
    ;) you are leaking info ;) :D :D
    • Funny
    Reactions: Admin
  • D AcornBot:
    Darren has left the room.
      D AcornBot: Darren has left the room.
      Top Bottom