- <head>
-
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
- <script>
- jQuery(function() {
- jQuery.support.placeholder = false;
- test = document.createElement('input');
- if('placeholder' in test) jQuery.support.placeholder = true;
- });
- $(function() {
- if(!$.support.placeholder) {
- var active = document.activeElement;
- $(':text').focus(function () {
- if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
- $(this).val('').removeClass('hasPlaceholder');
- }
- }).blur(function () {
- if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
- $(this).val($(this).attr('placeholder')).addClass('hasPlaceholder');
- }
- });
- $(':text').blur();
- $(active).focus();
- $('form:eq(0)').submit(function () {
- $(':text.hasPlaceholder').val('');
- });
- }
- });
- </script>
- <style>
- .hasPlaceholder {
- color: #777;
- }
- </style>
-
-
-
- <script type="text/javascript">
- function validateForm()
- {
- var name=document.forms["myForm"]["name"].value;
- var email=document.forms["myForm"]["email"].value;
- var msg= document.forms["myForm"]["message"].value;
-
- if (name==null || name=="")
- {
- alert("Name must be filled out");
- return false;
- }
- if (email==null || email=="")
- {
- alert("E-mail must be filled out");
- return false;
- }
- if(msg==null || msg=="")
- alert("Message must be filled out");
- return false;
- }
-
- </script>
-
-
- </head>
-
- <body>
-
- <FORM name="myForm" method="post" onsubmit="return validateForm()">
- <table style="margin-left: 20px;" cellpadding="0" cellspacing="0" border="0">
- <tr>
- <td><input class="rounded" type="text" name="name" placeholder="Navn" /></td>
- </tr>
- <tr>
- <td><input class="rounded" type="text" name="email" placeholder="E-mail" /></td>
- </tr>
- <tr>
- <td><textarea class="rounded" rows="5" id="message" cols="40" placeholder="Besked"></textarea></td>
- </tr>
-
- <tr>
- <td><input type="submit" value="Submit"></td>
- </tr>
- </table>
- </FORM>
-
-
-
-
- </body>
- </html>
TUTORIAL: Watermark Text Boxes(HTML/Javascript/jQuery)
http://www.ozzu.com/javascript-tutorials/tutorial-watermark-text-boxes-html-javascript-jquery-t106384.htmlHvorfor viser den ikke besked i internet explorer.?
Kan man lave det på en anden måde..??
Indlæg senest redigeret d. 26.06.2012 21:04 af Bruger #16802