Solved

tool tip for error message

Posted on 2010-09-04
6
928 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
ID: 33605372
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
ID: 33605443
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
ID: 33605451
z-index does nothing by itself. In this case, you probably want to use "position:absolute" with it.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

776 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