JS - Display a msg for only a few seconds

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Mar 2009
Posts: 14
Reputation: deadmancoder is an unknown quantity at this point 
Solved Threads: 0
deadmancoder's Avatar
deadmancoder deadmancoder is offline Offline
Newbie Poster

JS - Display a msg for only a few seconds

 
0
  #1
Sep 16th, 2009
i have a form.. i validated it..
if the form has an empty field, instead of popping up an alert box, i need to display a message that goes off say after 5 seconds..
any idea of how to do it?
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: JS - Display a msg for only a few seconds

 
1
  #2
Sep 18th, 2009
Originally Posted by deadmancoder View Post
i have a form.. i validated it..
if the form has an empty field, instead of popping up an alert box, i need to display a message that goes off say after 5 seconds..
any idea of how to do it?
You can create or display and HTML Element, that has the message.

Example of creating one:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var msg = documement.createElement('div');
  2. msg.innerHTML = 'Your message';

Then attach that div to whatever element you want it to display on:

eg:

HTML:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <p class="field">
  2. <label for="form-field-id">Label</label>
  3. <input id="form-field-id" name="form-field-id" />
  4. </p>

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. // create message element
  2. var msg = documement.createElement('div');
  3. msg.innerHTML = 'Your message';
  4. // attach it to the DOM
  5. var field = document.getElementById('form-field-id');
  6. field.parentNode.appendChild(msg);

That would append it as a child of <p class="field"> which is the parentNode of <input id="form-field-id" name="form-field-id" />.

To remove it you set a timer.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. clearTimeout(timer);
  2. timer = setTimeout(function() {
  3. msg.parentNode.removeChild(msg);
  4. }, 5000);
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC