Solved

tool tip for error message

Posted on 2010-09-04
6
925 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SharePoint 2013 List with Ratings 6 37
Don't understand jquery promises 6 37
Centering Vertically 3 28
Angular - break the dataset in chunks? 7 39
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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

13 Experts available now in Live!

Get 1:1 Help Now