It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

JS Form Validation Alert Messages

JS Form Validation Alert Messages

Postby tech_angel420 on Mon Jan 24, 2005 4:00 pm

Is there any way to get form validation alerts (I.E. "The first name field must not be left blank.") to appear on the page rather than displaying on the page? And if so, can the font/color properties be edited? An example of this might be done would be very much appreciated. Thanks.
tech_angel420
 
Posts: 27
Joined: Thu Dec 16, 2004 4:02 pm

Postby tech_angel420 on Mon Jan 24, 2005 4:53 pm

An example of how this is done can be found on Amazon.com. If there is a problem with a form, the page refreshes and a box is displayed above the form marked Important Message and then all the problems with the form are displayed beneath the actual form field. How the heck is this accomplished??? I tried viewing source and wasn't able to really decipher what was going on... HELP PLEASE!
tech_angel420
 
Posts: 27
Joined: Thu Dec 16, 2004 4:02 pm

Postby Malcolm on Mon Jan 24, 2005 7:03 pm

They're probably using a PHP or ASP solution but something like this can also work:

Code: Select all
<script type="text/javascript">
function check(){
   document.getElementById('alerts').innerHTML="";
   //your checking would go here
   if( 1==1){
      document.getElementById('alerts').innerHTML=document.getElementById('alerts').innerHTML+" New alert message!<br />";
   }
}
</script>
<div id="alerts" style="color:#f00;font-weight:bold;">
</div>
<input type="button" value="Click Me!" onclick="check();" />
Image
User avatar
Malcolm
100+ Club
 
Posts: 198
Joined: Thu Oct 07, 2004 9:53 pm
Location: Ontario, Canada


Who is online

Users browsing this forum: No registered users and 5 guests