Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

tool tip for error message

Posted on 2010-09-04
6
Medium Priority
?
936 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 35

Accepted Solution

by:
gr8gonzo earned 1600 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 43

Assisted Solution

by:David S.
David S. earned 400 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

916 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