Jquery and search form problem -
i can't jquery code clear search form when user clicks in search field can tell me i'm doing wrong?
jquery
$('#text').focus(function () { if ($(this).val() == $(this).attr("title")) { $(this).val(""); } }).blur(function () { if ($(this).val() == "") { $(this).val($(this).attr("title")); } }); $("#searchform").submit(function() { $("#text").each(function() { if($(this).val() == this.title) { $(this).val(""); } }); });
html5 code
<header id="header"> <div id="header-con"> <h1> <a href="" title=""><img src="" alt="" /></a> </h1> <nav id="nav"> <ul> <li>a href="" title=""></a></li> <li>a href="" title=""></a></li> <li>a href="" title=""></a></li> <li> <form method="post" action="" id="searchform"> <fieldset> <input type="text" name="search" size="38" value="search..." title="search..." id="text" /> <input type="submit" name="submit" value="search" id="sbutton" /> </fieldset> </form> </li> </ul> </nav> </div> </header>
since you're using html5, why aren't using placeholder
attribute?
<input type="text" name="search" size="38" placeholder="search..." id="text" />
...and done. no javascript.
Comments
Post a Comment