943,793 Members | Top Members by Rank

Ad:
Sep 16th, 2009
0

JS - Display a msg for only a few seconds

Expand 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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
deadmancoder is offline Offline
14 posts
since Mar 2009
Sep 18th, 2009
1

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

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);
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Line numbering for javascript.
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Access content page texbox from javascript in JS file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC