Solved

tool tip for error message

Posted on 2010-09-04
6
921 Views
Last Modified: 2012-05-10
i have a error message using jquery. i want to apply z-index and come top on other elements.
in this example i want the error message to come on top of the hello word.
its going to the left, and not coming on top. pl help.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script>
<style type="text/css">
.error { float: left; color: red; padding-left: .5em; vertical-align: top; border:1px solid red; z-index:10000; }
.red { color:red; }
</style>
<script>
$(document).ready(function(){
  $("#commentForm").validate({
    rules: {
      username: "required"     
    },
    errorPlacement: function(err,el) {
      var br = $('<br>');
      $(el).before(br);
      err.insertBefore(br);
    }
  });
});
</script>   
</head>
<body>
  <form id="commentForm" method="get" action="">
        <table width="600" cellpadding="2" cellspacing="0">
        <tr><td colspan="2">hello hello hello hello hello hello hello hello hello hello hello hello hello hello hellohellohellohello</td></tr>
		<tr>
            <td width="200px">Username<span class="req">*</span></td>
            <td width="400px"><input id="Username" type="text" name="username" size="25" minlength="2" /></td>
        </tr>       
     </table>           
     <input class="submit" type="submit" value="Submit"/> 
  </form>
</body>
</html>

Open in new window

0
Comment
Question by:yingwho
6 Comments
 
LVL 34

Accepted Solution

by:
gr8gonzo earned 400 total points
Comment Utility
Try this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<script src="http://code.jquery.com/jquery-latest.js"></script>

<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script>

<style type="text/css">

.error { color: red; padding-left: .5em; vertical-align: top; border:1px solid red; z-index:10000; }

.red { color:red; }

</style>

<script>

$(document).ready(function(){

  $("#commentForm").validate({

    rules: {

      username: "required"     

    },

    errorPlacement: function(err,el) {

      err.appendTo($("#errorHolder"));

    }

  });

});

</script>   

</head>

<body>

  <form id="commentForm" method="get" action="">

        <table width="600" cellpadding="2" cellspacing="0">

        <tr><td colspan="2"><div id='errorHolder' style='clear:both'></div>hello hello hello hello hello hello hello hello hello hello hello hello hello hello hellohellohellohello</td></tr>

		<tr>

            <td width="200px">Username<span class="req">*</span></td>

            <td width="400px"><input id="Username" type="text" name="username" size="25" minlength="2" /></td>

        </tr>       

     </table>           

     <input class="submit" type="submit" value="Submit"/> 

  </form>

</body>

</html>

Open in new window

0
 

Author Comment

by:yingwho
Comment Utility
gr8, thanks. but when i said error message should come on top of hello, it does not mean above.
what i meant was using z-index coming on top overlapping the hello just above the textbox.
0
 
LVL 42

Assisted Solution

by:David S.
David S. earned 100 total points
Comment Utility
z-index does nothing by itself. In this case, you probably want to use "position:absolute" with it.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now